Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert dialog styling not changing multichoice items text color

I am using a style to well, style my Alert Dialog, most of it is styled as you can see below but the multichoice items are not getting the color change. I would also like to have the checkboxes in white but am not sure how to do that.

Alert Dialog:

android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this, R.style.AlertDialogDarkBlue);

builder.setTitle("Faulty Part");

final ArrayList<Integer> selectedFaults = new ArrayList<>();

builder.setMultiChoiceItems(faultsList, null, new DialogInterface.OnMultiChoiceClickListener(){
    @Override
    public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
        if (isChecked) {
            // If the user checked the item, add it to the selected items
            selectedFaults.add(indexSelected);
        } else if (selectedFaults.contains(indexSelected)) {
            // Else, if the item is already in the array, remove it
            selectedFaults.remove(Integer.valueOf(indexSelected));
        }
    }
});

builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {

    }
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();

        onResume();
    }
});

android.app.AlertDialog alert = builder.create();

alert.show();

AlertDialogBlue style:

<style name="AlertDialogDarkBlue" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">@color/colorWhite</item>
    <item name="textColorAlertDialogListItem">@color/colorWhite</item>
    <item name="android:background">@color/colorDarkBlue</item>
</style>

How it currently looks:

enter image description here enter image description here

like image 456
Lewis Smith Avatar asked Jun 18 '18 09:06

Lewis Smith


1 Answers

  1. To fix the text color to white, just extend in your custom Style the AppCompat.Dark instead of the AppCompat.Light.

  2. To edit the CheckBoxes selected color, you can override the colorAccent in your custom style and it will be applyied only to the element using that style.

This is an example:

<style name="AlertDialogDarkBlue" parent="Theme.AppCompat.Dark.Dialog.Alert">
    <item name="android:textColor">@color/colorWhite</item>
    <item name="textColorAlertDialogListItem">@color/colorWhite</item>
    <item name="android:background">@color/colorDarkBlue</item>
    <!-- those to edit the color of checkboxes (I don't remember if both are needed or just one) -->
    <item name="android:colorAccent">@color/dialogCheckboxesColor</item>
    <item name="colorAccent">@color/dialogCheckboxesColor</item>
</style>

Hope this helps

like image 79
Pier Giorgio Misley Avatar answered Oct 20 '22 11:10

Pier Giorgio Misley