简体   繁体   English

白日梦与透明背景

[英]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. 但是,当我启动白日梦时,背景只有1秒透明。 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? 这个问题可能有你需要的答案: 如何在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. 幸运的是,您可以访问DreamService的窗口。 So what you can do in your DreamService class is the following: 那么您可以在DreamService类中执行以下操作:

 @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 ;-) 确保您的DreamService布局具有透明背景;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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