2012-11-08 60 views
1

我知道這個問題的答案必須圍繞地方,但我一直沒能找到它......的Android AlertDialog與自定義寬度

我有一個自定義AlertDialog,不管我怎樣設置參數在XML文件和/或Java代碼中,對話框始終以全屏寬度顯示。

現在,我的佈局文件是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/color_picker_dlg_root" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

<TableRow> 
[...] 
</TableRow> 
</TableLayout> 

,我在代碼中創建的AlertDialog這樣的:

layout = inflater.inflate(R.layout.color_picker_dlg, (ViewGroup) findViewById(R.id.color_picker_dlg_root)); 
builder = new AlertDialog.Builder(this); 
builder.setView(layout); 
[...] 
dialog = builder.create(); 

...並在對話框依然佔據了所有的屏幕寬度。

我能做些什麼來包裝其內容?

在此先感謝。

回答

0

我對我的對話有同樣的問題。爲了治癒它,我不得不用對話框主題來設置我的對話框。不知道如何通過提示對話框來做到這一點,但是要修改常規對話框的代碼。

dialog = new Dialog(context, R.style.CustomDialog); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.dialog_custom_blank); 
    dialog.setCancelable(isCancelable); 

這裏是CustomDialog主題

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="CustomDialog" parent="android:Theme.Dialog"> 

     <item name="android:layout_width">wrap_content</item> 
     <item name="android:layout_height">wrap_content</item> 
     <item name="android:windowIsFloating">true</item> 
     <item name="android:windowNoTitle">true</item> 

    </style> 

</resources> 

如果您想treally想進入對話框,並創建自己的自定義可重複使用的對話框不是在我的網站看看教程

http://www.androidianlabs.com/custom-android-dialogs.html