【发布时间】:2020-07-17 14:48:10
【问题描述】:
为什么我的提醒对话框不适应我手机的深色模式?当在我的手机中激活暗模式时,两个按钮的文本几乎看不到,而标题和消息的颜色是相反的。为什么按钮颜色也不反转?该图标在非深色模式下也不会很好地显示。如何解决所有这些问题?
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.title))
builder.setMessage(getString(R.string.message))
builder.setPositiveButton(getString(R.string.positive)) { dialog, which ->
Toast.makeText(applicationContext, getString(R.string.pos_toast), Toast.LENGTH_LONG).show()
}
builder.setNegativeButton(getString(R.string.negative)) { dialog, which ->
Toast.makeText(applicationContext, getString(R.string.negative_toast), Toast.LENGTH_LONG).show()
}
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.show()
我的 stiles.xml:
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="generalnotitle" parent="MyTheme">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
【问题讨论】:
-
您使用的是哪个应用主题?
-
@GabrieleMariotti 请参阅编辑。
标签: android kotlin android-alertdialog android-theme material-components-android