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

标签 android android-alertdialog customdialog

我已经创建了自己的(自定义)对话框。但是想要它的风格像原来的一样Alert Dialog . IE。底部有深色标题背景和灰色按钮背景。 是否有任何现成的 xml 具有相同的? (所以,我不会担心确切的颜色、高度、字体大小等)

最佳答案

此答案不正确

使用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 list 中应用,如 referenced here :

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

或使用 setTheme(int) 进入 Activity .但是,这似乎不是推荐的做法。 bug report 中显示的简单示例代码.

关于android - 如何使自定义对话框看起来像警报对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5452382/

相关文章:

android - Proguard 告诉我 'Please correct the above warnings first.' 。如何解决外部 jar 的引用?

android - 如何关闭自定义android.support.v7.app.AlertDialog.Builder?

android - 如何在对话框中实现 onWindowFocusChange() 方法 (Android)

android - 带有MVVM的Android自定义对话框

android locationlistener 注销监听后继续调用onlocationChanged

android - parse.com java.lang.ClassCastException : java. util.HashMap 无法转换为 org.json.JSONObject

android - ListView android中的复合列表项没有触发上下文菜单

Android AlertDialog - 标题背景颜色

android - 如何使自定义对话框更宽?

java - 如何在显示 android 后更改自定义对话框中 View 的可见性