4

I'm trying to implement a daydream service with a transparent background.

I wrote the following code:

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    setContentView(R.layout.mydream);
    getWindow().setBackgroundDrawable(new ColorDrawable(0));
    .
    .
    .
}

But when I start up the daydream, the background is only transparent for 1 second. After that it turns to black background.

Can anyone help me with this?

0s0ft
  • 76
  • 5

3 Answers3

0

This question may have the answer you need: How do I create a transparent Activity on Android?

You can do that by creating a Transparent theme and applying it to your activity.

Community
  • 1
  • 1
Luiza Utsch
  • 167
  • 2
  • 15
0

After a very long investigation found a solution

you can access to window.decorView layout params and set dimming to 0f and it will make your screensaver window transparent,

here is my code

 (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)
Rob
  • 886
  • 9
  • 16
-1

Luckily you can access the window of the DreamService. So what you can do in your DreamService class is the following:

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

Make sure your layout of the DreamService has a transparent background ;-)

moh
  • 53
  • 1
  • 7