2012-11-08 63 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