2014-01-31 162 views
5

我想删除对话框外部的透明黑色背景。如何删除对话框外部的透明黑色背景

enter image description here

我试着用:

final Dialog dialog = new Dialog(this); 
     dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE)); 
     this.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.WHITE)); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.setContentView(R.layout.spinner_layout); 
     getWindow().getDecorView().setBackgroundResource(android.R.color.transparent); 

回答

7

你的问题已经从链路回答here

代码:

添加到您的styles.xml:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="Theme.DoNotDim" parent="android:Theme"> 
    <item name="android:backgroundDimEnabled">false</item> 
    </style> 
</resources> 

,然后应用主题,你的活动:

<activity android:name=".SampleActivity" android:theme="@style/Theme.DoNotDim"> 
16

除了chuky的回答;

如果您的minSdkVersion值大于或等于14,则可以使用setDimAmount()方法。

dialog.getWindow().setDimAmount(float amount); 

根据reference;

金额新的暗淡量,从0为无昏暗到1为暗淡。

As stated previously,可以清除窗口标志。

5

希望这有助于你...

 dialog.getWindow().getDecorView().setBackgroundResource(android.R.color.transparent); 
     dialog.getWindow().setDimAmount(0.0f); 
     dialog.show();