具有自定义宽度的Android AlertDialog

具有自定义宽度的Android AlertDialog,android,dialog,width,Android,Dialog,Width,我知道这个问题的答案一定在某个地方,但我一直没能找到 我有一个自定义的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_

我知道这个问题的答案一定在某个地方,但我一直没能找到

我有一个自定义的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>
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();
。。。对话框仍然占据了整个屏幕的宽度

我能做些什么来包装它的内容


提前谢谢。

我的对话框也有同样的问题。为了解决这个问题,我必须用对话主题设置对话。不知道如何使用警报对话框,但下面是常规对话框的代码

    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>

包装内容
包装内容
符合事实的
符合事实的
如果你真的想进入对话框并创建你自己的自定义可重用对话框,那么可以在我的网站上查看教程