如何更改 MaterialAlertDialog 中项目的文本颜色?

Pau*_*rat 2 android android-alertdialog material-design material-components material-components-android

我正在尝试更改单个选择 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>
Run Code Online (Sandbox Code Playgroud)

我还尝试使用 textAppearanceListItem 更改项目的文本颜色,但它不起作用。

Gab*_*tti 7

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

<style name="AlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="android:checkedTextViewStyle" ns2:ignore="NewApi">@style/myCheckedTextView</item>
</style>   
Run Code Online (Sandbox Code Playgroud)

和:

  <style name="myCheckedTextView" parent="@style/Widget.MaterialComponents.CheckedTextView">
    <item name="android:textColor">@color/.....</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

否则你也可以使用:

<style name="AlertDialog"  
   parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
     <item name="colorSecondary">@color/selected</item> <!-- selected -->
 </style> 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述