Alert dialog style does not change the multi-select item text color… here is a solution to the problem.
Alert dialog style does not change the multi-select item text color
I’m using a style to style my alert dialog, most of which look like this, but the multi-select items don’t change color. I’d also like to set the checkbox to white, but I’m 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>
What it looks like at its current state:
Solution
To fix the text color to white, simply extend
AppCompat.Dark
instead ofAppCompat.Light
in your custom style.To edit the color selected by
CheckBoxes
, you can override thecolorAccent
in a custom style, which will only be applied to elements that use that style.
Here 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 that helps