2

I'm trying to change the color of AlertDialog with MultiChoiceItems

Java :

   private void displayMultiSelectDialog() {
        emoji = getResources().getStringArray(R.array.photo_editor_emoji);
        boolean[] checkedItems = new boolean[emoji.length];
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this, R.style.DialogTheme);
        dialogBuilder.setTitle("Select Emoji");
        dialogBuilder.setMultiChoiceItems(convertListEmoji(emoji), checkedItems,
                (dialogInterface, which, isSelected) -> {
                    if (isSelected) {
                        selectedEmoji.add(emoji[which]);
                    } else {
                        selectedEmoji.remove(emoji[which]);
                    }
                }
        );
        dialogBuilder.setPositiveButton("Done", (dialog, which) -> showSelectedColors());
        dialogBuilder.create().show();
    }

XML :

   <style name="DialogTheme">
        <item name="android:background">#000</item>
        <item name="android:textColor">#586eea</item>
        <item name="android:textSize">18sp</item>
        <item name="android:textColorPrimary">#586eea</item>
        <item name="android:colorAccent" tools:targetApi="lollipop">#586eea</item>
    </style>

but I have a problem my AlertDialog background, it's BLACK so the checkbox items look invisible

enter image description here

how to make the checkbox looks like this :

enter image description here

Massive thanks in advance

Community
  • 1
  • 1
  • 1
    Try https://stackoverflow.com/questions/26447709/how-to-set-checkbox-border-color. – ADM Jun 03 '19 at 04:17

2 Answers2

1

Try setting a custom theme to your checkbox.

Add style in your styles.xml

<style name="MyCheckBox" parent="Theme.AppCompat.NoActionBar">
    <item name="colorControlNormal">#000</item>   <!-- normal border color  -->
    <item name="colorControlActivated">#000</item> <!-- activated color  -->
    <item name="android:textColor">#FFFF3F3C</item> <!-- text color -->
</style>

and set this style as your checkbox's theme as below:

<CheckBox android:id="@+id/check_agree"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:text="I agree"
          android:theme="@style/MyCheckBox"/>   <!-- here apply your checkbox style -->
0

<CheckBox
  ...
  android:buttonTint="@color/tint_color" />

minSdkVersion is 21+ use android:buttonTint attribute to update the color of a checkbox:

Sai Jayant
  • 366
  • 2
  • 14