android – How to change the text color of items in MaterialAlertDialog?-ThrowExceptions

Exception or error:

I am trying to change the text color of the items in a single choice MaterialViewAlertDialog. I achieved to change the “RadioButton” color and the title color but I can’t change the text color of the items. For now I am using the following style:

<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>

I also tried to cahnge the text color of the items with textAppearanceListItem but it didn’t work.

How to solve:

To change the color of the text in the items you can use something like:

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

with:

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

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *