2012-10-08 31 views
0

這是我有嘗試:AlertDialog沒有其股票的背景

public AlertDialogEx(final Context context, View lytCustom) 
    { 
     // Set your theme here 
     super(context, android.R.style.Theme_Translucent); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 

     // This is the layout XML file that describes your Dialog layout 
     this.setView(lytCustom); 
//  this.setContentView(lytCustom); 
    } 

,並沒有擺脫黑色背景:

enter image description here

使用setContentView(),而不是setView()投臭名昭着的「requestFeature()必須在添加內容之前調用」消息,遺憾的是沒有明顯的原因。我怎樣才能實現我的目標?

回答

0

你應該在XML佈局文件中定義對話框的背景/ 像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="?windowBackground" 
android:orientation="vertical" > 
......................... 
body of your dialog 
........................... 
</LinearLayout> 

或者你也可以做到這一點programaticaly

view.setBackgroundColor(color) 
0

結束了常規全屏活動,而不是AlertDialog使用主題@android:style/Theme.Translucent.NoTitleBar,並且有很多透明背景。