Daydream带有透明背景

4
我正在尝试实现一个带有透明背景的待机服务。我编写了以下代码:
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    setContentView(R.layout.mydream);
    getWindow().setBackgroundDrawable(new ColorDrawable(0));
    .
    .
    .
}

但是当我启动Daydream时,背景只能透明1秒钟。之后它就会变成黑色背景。

有人可以帮我解决这个问题吗?

3个回答

0

仍然无法运行,仍有黑色梦幻服务背景。 - Rob
不起作用,仍然有黑色梦幻服务背景。 - undefined

0
经过漫长的调查,我找到了一个解决方案。
你可以访问window.decorView布局参数并将暗淡度设置为0f,这将使你的屏幕保护窗口透明。
以下是我的代码。
 (window.attributes).apply {
     dimAmount = 0f
     format = PixelFormat.RGBA_8888 // I also suggest to set color format PixelFormat.RGBA_8888 and bellow all this code set window.decorView.setBackgroundColor(Color.TRANSPARENT)
     windowManager.updateViewLayout(window.decorView, this)
  }
window.decorView.setBackgroundColor(Color.TRANSPARENT)

-1

幸运的是,您可以访问DreamService的窗口。因此,在DreamService类中,您可以执行以下操作:

 @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        setInteractive(true);
        setContentView(R.layout.dream_service);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00FFFFFF")));
    }

请确保您的DreamService布局具有透明背景 ;-)


无法运行,依旧是黑色梦幻服务背景。 - Rob

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接