【问题标题】:Change default dialog buttons text color without changing colorAccent attribute更改默认对话框按钮文本颜色而不更改 colorAccent 属性
【发布时间】:2017-10-20 03:23:06
【问题描述】:

在 android 中,默认对话框按钮(负、中性和正)文本颜色与 colorAccent(在 colors.xml 中)属性相同,但我想在不更改 colorAccent 属性的情况下设置一些不同的颜色。我到处寻找,但找不到任何方法。

【问题讨论】:

标签: android xml android-alertdialog


【解决方案1】:

在主 AppTheme 中指定 alertDialogTheme,然后在该主题中定义不同的 colorAccent,这是特定于 AlertDialogs 的:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="alertDialogTheme">@style/AlertDialog</item>
</style>

<style name="AlertDialog" parent="@style/ThemeOverlay.AppCompat.Dialog.Alert">
    <item name="colorAccent">@color/yourColor</item>
</style>

【讨论】:

  • 发帖前检查过,再检查一次。你使用 AlertDialog v7 吗?
  • 不,我使用的是android.app.AlertDialog。我应该使用什么?
  • android.support.v7.app.AlertDialog
  • 我改成 v7.AlertDialog 并且成功了,谢谢@gurgen
猜你喜欢
  • 2019-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-26
  • 2014-05-12
  • 1970-01-01
  • 2013-12-24
  • 2015-02-27
相关资源
最近更新 更多