2016-02-05 79 views
1

I want to do following我想要在客户对话框背后的蓝色半透明。但我没有得到蓝色android-透明背景的对话框(任何颜色)

下面是对话声明代码:

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

这里是我的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> 

回答

2

好吧,我得到了解决

首先要改变主题。 不要做客户主题。使用android.R.style.Theme_Translucent_NoTitleBar_Fullscreen

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

,而不是自定义主题,并添加以下内容:

window.setBackgroundDrawableResource(R.color.dialog_back); 

全码:从资源文件color.xml,并在最后

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

使用的颜色,但并非最不重要的不要”吨忘记减少颜色的不透明度。