gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 07:42:51 27 4
gpt4 key购买 nike

如果应用程序调用了 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com