【发布时间】:2011-03-27 20:54:48
【问题描述】:
我创建了自己的(自定义)对话框。但希望有它的风格像原来的Alert Dialog。 IE。底部有深色标题背景和灰色按钮背景。 有没有相同的现成xml? (所以,我不会担心确切的颜色、高度、字体大小等)
【问题讨论】:
标签: android android-alertdialog customdialog
我创建了自己的(自定义)对话框。但希望有它的风格像原来的Alert Dialog。 IE。底部有深色标题背景和灰色按钮背景。 有没有相同的现成xml? (所以,我不会担心确切的颜色、高度、字体大小等)
【问题讨论】:
标签: android android-alertdialog customdialog
这个答案不正确
使用Theme.Dialog.Alert
来自themes.xml:
<!-- Default theme for alert dialog windows, which is used by the
{@link android.app.AlertDialog} class. This is basically a dialog
but sets the background to empty so it can do two-tone backgrounds. -->
<style name="Theme.Dialog.Alert" parent="@android:style/Theme.Dialog">
<item name="windowBackground">@android:color/transparent</item>
<item name="windowTitleStyle">@android:style/DialogWindowTitle</item>
<item name="windowIsFloating">true</item>
<item name="windowContentOverlay">@null</item>
</style>
这可以在 XML 布局或 Android 清单中应用,如 referenced here:
<activity android:theme="@android:style/Theme.Dialog.Alert">
或使用setTheme(int) 进入活动。但是,这似乎不是推荐的做法。此bug report 中显示的简单示例代码。
【讨论】:
<style name="Theme.Dialog"> 部分,它列出了制作普通对话框所需的所有必要样式。如果您不确定如何使用它们,请参阅Applying Styles and Themes。您还可以重写您的对话框类以包含使用或扩展AlertDialog.Buider
我也遇到了这个问题,想创建一个和 AlertDialog 有相同 UI 的 Activity。我发现这有点困难。最后,我创建了一个透明的活动,并在其中启动了一个 AlertDialog 来解决。
【讨论】: