Pierre
Pierre

Reputation: 77

Android Alert Dialog Checkbox Text

enter image description hereI have a MaterialAlertDialogBuilder, I am passing to it the following ContextThemeWrapper:

<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="Theme.AppCompat.Dialog.Alert">
    <item name="android:background">?customfrontcolour</item>
    <item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
    <item name="buttonBarNegativeButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
    <item name="colorControlNormal">?customtextcolor</item>
    <item name="colorControlActivated">?customtextcolor</item>
</style>

I can't figure out how to change the color of the of the text next to checkbox ( "Beirut" ).

I tried all adding all the following to my MyThemeOverlay.MaterialComponents.MaterialAlertDialog:

"textColorAlertDialogListItem"
"android:textColor"
"android:textColorPrimary"

Upvotes: 2

Views: 572

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364421

You have to define a custom style for the Dialog using the android:checkedTextViewStyle attribute:

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

Then define:

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

Then just show the dialog with:

  new MaterialAlertDialogBuilder(this,
      R.style.dialogCheckedStyle)
      .setMultiChoiceItems(....)
      //...
      .show();

enter image description here

The default color is defined by this selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:alpha="@dimen/material_emphasis_medium" android:color="?attr/colorOnSurface"/>
</selector>

Upvotes: 4

Related Questions