android - AlertDialog 样式和颜色

标签 android styles android-alertdialog

我正在尝试创建如下所示的警告对话框

enter image description here

但我不明白为什么,当我在我的设备上启动应用程序时,我会看到如下所示的对话框:enter image description here

我学习了很多教程,但仍然看到这样的警告对话框。 代码非常标准,所以我不会发布它,但如果需要我会发布。 我的设备在 4.3 android 上运行。 我的问题:警报样式是否会随着设备 API Lvl 的变化而变化?如果是这样,我该怎么做才能像第一张图片一样创建对话框?我会使用布局 inflater 创建自定义对话框,但我想要那些很酷的按钮。

最佳答案

问题出在主题上。

第一个屏幕截图中的对话框使用“Holo Light”主题,而第二个屏幕截图使用“Theme”主题。

创建 AlertDialog 有两个选项,如第一张图片所示。

  1. 您可以更改应用程序或 Activity 的主题以继承自 Holo.Light(参见 Android's Styles & Themes guide)。这将更改整个应用程序或 Activity 中 AlertDialogs 的外观。

  2. 您可以通过以下方式为单个 AlertDialog 设置主题:

new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog)) .setTitle("演示对话框") .setMessage("此 AlertDialog 使用主题 android.R.style.Theme_Holo_Light_Dialog。") 。创造() .show();

这些选项中的任何一个都会产生以下结果:

AlertDialog with Holo Light theme

关于android - AlertDialog 样式和颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26196248/

相关文章:

android - 如何区分android中的布局文件夹?

android - 如何测试我们是否在 Gradle 中进行发布构建

html - 下拉菜单随着浏览器变小而改变宽度

wpf - 使用样式设置WPF控件背景图像?

Javascript:在没有 JQuery 的情况下使用单选按钮更改样式?

android - AlertDialog 未显示

android - 将数据库放入android项目

Android java.lang.IllegalArgumentException : Service not registered

android - Android Studio 中的alertDialog 倒计时

android - 如何实现自定义的 AlertDialog View