android - AlertDialog 使用什么主题来自动调整日/夜主题的颜色

标签 android themes android-alertdialog

如果应用程序调用了 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);,它应该显示深色主题,如果不是,则应用程序使用浅色主题。

拥有 AlertDialog.Builder(this),并希望应用一个主题,以便在 MODE_NIGHT 中显示深色主题的对话框,否则对话框显示浅色主题,如下所示(但是这个 android.R.style.Theme_Material_Dialog 会导致对话框始终处于深色主题)

AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog)

AlertDialog 是否只有一个主题?还是必须定义两个主题并检查模式,然后分别用主题编码?

最佳答案

styles.xml 中定义您的警报对话框

<style name="MyDialogStyle" parent="Theme.AppCompat.DayNight.Dialog.Alert"/>

在你的代码中

AlertDialog.Builder(this, R.style.MyDialogStyle)

试试吧!

关于android - AlertDialog 使用什么主题来自动调整日/夜主题的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51901765/

相关文章:

java - 为什么需要显式转换?

Android 从后台恢复给我空白 fragment

Java/安卓 : SQLite or file for indexing?

php - 在没有 Web 界面的情况下在 Drupal 中切换主题

android - AlertDialog如何在输入后关闭键盘

android - 使对话框宽度为全屏

android - 刷新 PopupWindow.dismiss 上的父 fragment

asp.net-mvc - Asp.Net MVC 主题,如何?

android - 为什么 Activity 中的 getApplicationContext().setTheme() 不起作用?

android - Kotlin中的对话框警报