Daydream with transparent background

456 Views Asked by At

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?

3

There are 3 best solutions below

0
On

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)
1
On

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.

1
On

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 ;-)