我目前正在创建一个自定义对话框(AlertDialog 对我的需求不够灵活)。我希望它看起来像 AlertDialog,具有众所周知的 AlertDialog 标头(请参见下面的图像)。
同时,在我的自定义对话框中,我有一个 ListView,我希望它看起来像 AlertDialog 的 ListView。我该如何做?
到目前为止,我在 attr 类中找到了 alertDialogTheme 和 alertDialogStyle,但我不知道如何使用它们。
使用自定义对话框时应该是这个样子:
它的样子是这样的(黑色背景,错误的标头):
我的布局非常基本,看起来像这样:
同时,在我的自定义对话框中,我有一个 ListView,我希望它看起来像 AlertDialog 的 ListView。我该如何做?
到目前为止,我在 attr 类中找到了 alertDialogTheme 和 alertDialogStyle,但我不知道如何使用它们。
使用自定义对话框时应该是这个样子:
![typical alertdialog with listview](https://istack.dev59.com/4miln.webp)
![custom](https://istack.dev59.com/bajwY.webp)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
这个 ListView 包含使用此布局的项目。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/icon_noimage" />
<TextView
android:id="@+id/text"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="18dp" />
</LinearLayout>
你有什么想法吗?
---> 使用带有自定义视图的alerdialog的解决方法,但现在我遇到了一些间隙问题: