警报对话框样式不更改多选项目文本颜色
Alert dialog styling not changing multichoice items text color
我很好地使用了一种样式,为我的警报对话框设计样式,其中大部分样式如下所示,但多选项目没有改变颜色。我也想将复选框设置为白色,但我不确定该怎么做。
警报对话框:
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>
它目前的样子:
要将文本颜色固定为白色,只需在您的自定义样式中扩展 AppCompat.Dark
而不是 AppCompat.Light
。
要编辑 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>
希望这对您有所帮助
您可以使用:
<item name="textColorAlertDialogListItem">@color/your_color</item>
我很好地使用了一种样式,为我的警报对话框设计样式,其中大部分样式如下所示,但多选项目没有改变颜色。我也想将复选框设置为白色,但我不确定该怎么做。
警报对话框:
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>
它目前的样子:
要将文本颜色固定为白色,只需在您的自定义样式中扩展
AppCompat.Dark
而不是AppCompat.Light
。要编辑
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>
希望这对您有所帮助
您可以使用:
<item name="textColorAlertDialogListItem">@color/your_color</item>