【问题标题】:How to change the text color of items in MaterialAlertDialog?如何更改 MaterialAlertDialog 中项目的文本颜色?
【发布时间】:2020-05-31 12:40:00
【问题描述】:

我正在尝试更改单选 MaterialViewAlertDialog 中项目的文本颜色。我实现了更改“RadioButton”颜色和标题颜色,但我无法更改项目的文本颜色。现在我使用以下样式:

<style name="AlertDialog" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
        <item name="android:titleTextColor">@color/colorText</item>
        <item name="android:textColorSecondary">@color/colorText</item>
        <item name="android:textColorAlertDialogListItem">@color/colorText</item>
</style>

我还尝试使用 textAppearanceListItem 更改项目的文本颜色,但没有成功。

【问题讨论】:

  • 你用java设置主题吗?
  • 是的,我设置了主题,例如 @color/colorText 正在工作。

标签: android material-design android-alertdialog material-components-android material-components


【解决方案1】:

要更改项目中文本的颜色,您可以使用以下内容:

<style name="AlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="android:checkedTextViewStyle" ns2:ignore="NewApi">@style/myCheckedTextView</item>
</style>   

与:

  <style name="myCheckedTextView" parent="@style/Widget.MaterialComponents.CheckedTextView">
    <item name="android:textColor">@color/.....</item>
  </style>

否则你也可以使用:

<style name="AlertDialog"  
   parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
     <item name="colorSecondary">@color/selected</item> <!-- selected -->
 </style> 

【讨论】:

  • 感谢您的回答,效果很好。但是 ns2:ignore="NewApi" 对我来说似乎没有必要(没有它我在 Android Studio 上没有警告)。添加 ns2:ignore="NewApi" 是否有特定原因?
  • 同@SuppressLint("NewApi")
猜你喜欢
  • 1970-01-01
  • 2011-01-13
  • 2012-07-01
  • 2019-09-21
  • 1970-01-01
  • 2020-09-17
  • 2018-12-09
  • 1970-01-01
相关资源
最近更新 更多