如果调用的应用程序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)
并尝试一下!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句