警告对话框样式不能更改多选项文本颜色

5

我正在使用样式来设置我的警告对话框,大多数内容都已经被设置成了你下面可以看到的样子,但是多选项并没有改变颜色。我还希望复选框是白色的,但是不确定该怎么做。

警告对话框:

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

当前的样子:

在此输入图片描述 在此输入图片描述


2
尝试扩展 AppCompat.Dark 而不是 AppCompat.Light - Pier Giorgio Misley
是的,你发现得很好。我该如何更改复选框选中的颜色? - Lewis Smith
抱歉,我不在电脑旁,下面是回答。 - Pier Giorgio Misley
3个回答

4
  1. 为了将文本颜色设置为白色,只需在您的自定义样式中扩展AppCompat.Dark而不是AppCompat.Light

  2. 要编辑CheckBoxes选定的颜色,可以在您的自定义样式中覆盖colorAccent,它仅适用于使用该样式的元素。

这是一个例子:

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

希望这有所帮助。

0

您可以使用:

<item name="textColorAlertDialogListItem">@color/your_color</item>

0

试试这个:

<item name="android:textColorAlertDialogListItem">@color/white</item>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接