gpt4 book ai didi

android - 警报对话框按钮具有不同的颜色集

转载 作者:行者123 更新时间:2023-11-29 22:53:12 27 4
gpt4 key购买 nike

enter image description here

你好,我有一个警告对话框。按钮是紫色的。是的,我可以使用以下方法更改文本的颜色:

          alertDialog.getButton(Dialog.BUTTON_NEGATIVE).
setTextColor(Color.parseColor("#000000"));

但是当它们被触摸时,会形成紫色调。我希望色调像我的应用程序的主色调一样是蓝色的,文本是黑色的。

这是我的警报风格:

<style name="MyCustomAlert2" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="colorAccent">@color/materialBlue</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="android:windowBackground">@drawable/custom_alert2</item>
<item name="colorControlNormal">@android:color/black</item>
<item name="colorControlActivated">@color/materialBlue</item>
<item name="textColorAlertDialogListItem">@android:color/black</item>
</style>

注意:上面链接的颜色都不是紫色。

感谢帮助

最佳答案

使用新的androidx.appcompat.app.AlertDialogMaterial components for android library .

只需使用类似的东西:

new MaterialAlertDialogBuilder(context)
.setTitle("...")
.setMessage("....")
.setPositiveButton("Ok", /* listener = */ null)
.setNegativeButton("Cancel", /* listener = */ null)
.show();

然后你可以自定义样式:

  <!-- Alert Dialog -->
<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
</style>

在这里您可以更改每个按钮:

  <style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#000000</item>
<item name="backgroundTint">@color/selector_bt</item>
</style>

enter image description here

您可以使用以下方式在您的应用主题中全局设置样式:

<item name="materialAlertDialogTheme">@style/MyThemeOverlay.MaterialComponents.MaterialAlertDialog</item>

或者你可以使用构造函数:

new MaterialAlertDialogBuilder(context,
R.style.MyThemeOverlay_MaterialComponents_MaterialAlertDialog)

关于android - 警报对话框按钮具有不同的颜色集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57711092/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com