我正在显示带有消息和确定按钮的警告对话框。但确定按钮的颜色和按钮的文字是相同的
context!!.alert ("this test message for the dialog aleat"){
okButton { context!!.toast("yeah it ok") }
}.show()
答案 0 :(得分: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>