看起来像 AlertDialog 的自定义对话框
我目前正在创建一个自定义对话框(alertdialog 不够灵活,无法满足我的需求)。我希望它看起来像一个 AlertDialog,带有众所周知的 AlertDialog 标题(见下图)。
我的自定义对话框中还有一个列表视图,我希望它看起来像 AlertDialog 的列表视图。我怎么能那样做呢?
到目前为止,我在 attr 中找到了alertDialogTheme 和alertDialogStyle。类,但我不知道如何使用它。
使用自定义对话框应该是什么样子:
它的外观(黑色背景,错误的标题):
我的布局非常基本,如下所示:
<?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>
列表视图包含使用此布局的项目
<?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 的解决方法,但现在我遇到了以下问题,但存在一些差距:
i'm currently creating a custom dialog (alertdialog is not flexible enough for my needs). and i want it to look like a AlertDialog, with that well kown AlertDialog header (see image below).
also i got a listview within my custom dialog and i want it to look like a listview of the AlertDialog. how could i do that?
so far i found alertDialogTheme and alertDialogStyle in the attr. class, but i don't know how to use it.
what it should look like using a custom dialog:
what it looks like (black background, wrong header):
my layouts are pretty basic and look like this:
<?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>
the listview contains items that use this layout
<?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>
any ideas?
---> workaround using alerdialog with custom view, but now i got the following problem with some gaps:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用典型的
AlertDialog
标题/标题创建普通的AlertDialog
,但随后将对话框的内容设置为使用自定义视图:这将导致外观正常的
AlertDialog
具有正常的标题,但内容将使用您想要的任何自定义视图。对于要显示为内容的 ListView,您只需根据需要重新创建 View,并将其用作我的示例中的
customLayout
即可。You can create a normal
AlertDialog
using the typicalAlertDialog
title/header but then set the content of the dialog to use a custom view:This will result in a normal looking
AlertDialog
with the normal looking title, but the content will use whatever custom view you want.For the ListView you want to display as the content, you are simply going to need to recreate the View as you see fit and use it as the
customLayout
in my example.