2012-04-27 104 views
2

對話框佈局的xml:安卓:更改自定義AlertDialog背景

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root_view" 
    android:padding="3dp" 
    android:background="@android:color/white" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    //...content... 

</TableLayout> 
上圖釘挖掘時,在地圖覆蓋

對話框實現:

AlertDialog.Builder builder; 

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE); 
View layout = inflater.inflate(R.layout.map_kap_dialog, 
        (ViewGroup) mapView.findViewById(R.id.root_view)); 

//prepare info to show... 
//info prepared 

//other preparations stuff 
builder = new AlertDialog.Builder(context); 
builder.setView(layout); 
dialog = builder.create(); 
dialog.setInverseBackgroundForced(true); 
dialog.setCanceledOnTouchOutside(true); 
//show it 
dialog.show(); 

,我看到的,當測試:

enter image description here

所以我想圍繞對話框的淺灰色背景(圍繞s quare白色空間)變成白色,所以它不會看起來很醜。誰能幫我?

回答

1

嘿設置你的視圖建設者創建這條灰色的線在上下,而不是你可以setView到你的dialog.like dialog.setView(layout,0,0,0,0);它會將你的佈局綁定到整體對話。

9

我有同樣的問題,我設法使用自定義對話框這樣來解決它:

public class CustomDialog extends Dialog { 
    public CustomDialog(Context context, View view) { 
     super(context); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(view); 
     getWindow().getDecorView().setBackgroundResource(android.R.color.transparent); 
    } 
} 
0

另一種選擇是從佈局中刪除android:background="@android:color/white"。然後警報對話框的默認淺灰色背景統一。 (因爲你在黑暗的主題上被迫反過來)至少它看起來不錯,值得一提。只是我的兩分錢。