android - Anko 警报文本颜色显示错误
问题描述
我正在显示带有消息和确定按钮的警报对话框。但是好的按钮颜色和按钮的文本是相同的
context!!.alert ("this test message for the dialog aleat"){
okButton { context!!.toast("yeah it ok") }
}.show()
解决方案
我已经使用以下代码实现了这一点。为我工作
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>
推荐阅读
- python-3.x - 没有处理程序的记录器日志记录
- r - 检查数据框中两列的相关性(在 R 中)
- bash - 当bash脚本在里面运行时如何锁定文件夹
- spring-boot - 如何在 Spring Boot 中关闭 liquibase 横幅?
- html - 响应式标题定位
- sql - 从 IDE 运行一个过程,而如果一个触发器调用它就会出错
- java - 带有字符串构造函数和实习生函数的 Java 字符串池
- android - Android 11(R) - 以编程方式查找“每次询问”或“仅此一次”权限?
- javascript - 笑话:如何使用 dom 设置 offsetWidth
- javascript - 如何正确禁用 JavaScript 中 HTML 元素的高亮显示?