2016-02-05 91 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(); 

使用的顏色,但並非最不重要的不要」噸忘記減少顏色的不透明度。