简体   繁体   English

android - 具有透明背景的对话框(带有任何颜色)

[英]android - Dialog with transparent background (with any color)

我想做以下 I want blue translucent behind custome dialog box. 我希望蓝色半透明的客户对话框背后。 but I am not getting blue color 但我没有得到蓝色

Here is code of dialog declaration: 这是对话框声明的代码:

final Dialog dialog = new Dialog(BookAppointmentActivity.this,R.style.TranslucentBlue );
                //Dialog dialog = new Dialog(BookAppointmentActivity.this,  android.R.style.Theme_Translucent_NoTitleBar_Fullscreen );

                dialog.setContentView(R.layout.customedialog);
                Window window = dialog.getWindow();
                window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));


                dialog.show(); 

Here is my style.xml 这是我的style.xml

<color name="transparent_green_color">@color/dialog_back</color>
    <style name="TranslucentBlue" parent="android:Theme.Translucent">
        <item name="android:windowBackground">@color/transparent_green_color</item>
    </style>

Ok I got the solution 好的,我得到了解决方案

First make change in theme. 首先要改变主题。 Don't make custome theme. 不要以客户为主题。 Use android.R.style.Theme_Translucent_NoTitleBar_Fullscreen 使用android.R.style.Theme_Translucent_NoTitleBar_Fullscreen

final Dialog dialog = new Dialog(BookAppointmentActivity.this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

instead of custom theme, and add following: 而不是自定义主题,并添加以下内容:

window.setBackgroundDrawableResource(R.color.dialog_back);

Full code: 完整代码:

final Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

dialog.setContentView(R.layout.customedialog);
Window window = dialog.getWindow();

window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

window.setBackgroundDrawableResource(R.color.dialog_back);
dialog.show();

Use color from your resource file color.xml and at last but not least don't forget to decrease the opacity of the color. 使用资源文件color.xml颜色,最后但不要忘记降低颜色的不透明度。

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

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