如何使自定义对话框看起来像警报对话框?

发布于 2024-10-28 01:46:34 字数 187 浏览 1 评论 0原文

我创建了自己的(自定义)对话框。但希望其风格像原始警报对话框。即底部有深色标题背景和灰色按钮背景。 是否有任何现成的 xml 具有相同的功能? (所以,我不会担心确切的颜色、高度、字体大小等)

I've created my own (custom) Dialog. But would like to have its style like original Alert Dialog. I.e. with dark title background and grey buttons background on the bottom.
Is there any ready-for-use xml with the same? (so, I wouldn't worry about exact colors, heights, font sizes etc.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红颜悴 2024-11-04 01:46:34

这个答案不正确

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 清单中,如 < a href="http://developer.android.com/guide/topics/ui/themes.html" rel="nofollow">在此处引用:

<activity android:theme="@android:style/Theme.Dialog.Alert">

或者使用 setTheme(int)。然而,这似乎不是推荐的做法。此错误报告中显示了简单的示例代码。

This answer is incorrect

Use Theme.Dialog.Alert

From 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>

This can then be applied within an XML layout or Android manifest, as referenced here:

<activity android:theme="@android:style/Theme.Dialog.Alert">

Or onto an Activity using setTheme(int). However, this does not seem to be a recommended practice. Simple sample code shown in this bug report.

巾帼英雄 2024-11-04 01:46:34

我也遇到了这个问题,想创建一个与AlertDialog具有相同UI的Activity。我发现有点困难。最后,我创建了一个透明的活动并在其中启动了一个AlertDialog来解决。

I also encountered this problem, wanted to create an Activity having the same UI as AlertDialog. I found it's a little difficult. Finally, I created a transparent activity and started an AlertDialog in it to resolve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文