首页 > 解决方案 > Anko 警报文本颜色显示错误

问题描述

我正在显示带有消息和确定按钮的警报对话框。但是好的按钮颜色和按钮的文本是相同的

context!!.alert ("this test message for the dialog aleat"){
            okButton { context!!.toast("yeah it ok") }
        }.show()

在此处输入图像描述

标签: androidkotlinkotlin-android-extensionsanko

解决方案


我已经使用以下代码实现了这一点。为我工作

     getContext()?.alert("me") {
            also {
                ctx.setTheme(R.style.CustomAlertDialog)
            }
            okButton {  getContext()!!.toast("Done") }
        }!!.show()

主题变化是

  <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="dialogTheme">@style/CustomAlertDialog</item>
</style>

<style name="CustomAlertDialog" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
  <item name="buttonBarPositiveButtonStyle">@style/btnStyle</item>
    <item name="android:textColor">@android:color/white</item>
</style>

<style name="btnStyle" parent="TextAppearance.AppCompat.Body1">
    <item name="android:textColor">@android:color/white</item>
</style>

推荐阅读