简体   繁体   中英

Daydream with transparent background

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM