Anko警报文本颜色显示错误

问题描述 投票:3回答:2

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

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

enter image description here

android kotlin kotlin-android-extensions anko
2个回答
3
投票

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

     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>

0
投票

我找到了完美的解决方案:

Theme.AppCompat...而不是styles.xml中使用Theme.MaterialComponents...

© www.soinside.com 2019 - 2024. All rights reserved.