Lew*_*ith 5 java android android-alertdialog
我正在使用一种样式来设计我的警报对话框,其中大部分的样式如下所示,但多选项目的颜色没有变化。我还想将复选框设置为白色,但不知道该怎么做。
警报对话框:
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();
Run Code Online (Sandbox Code Playgroud)
AlertDialog蓝色风格:
<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>
Run Code Online (Sandbox Code Playgroud)
目前的样子:
要将文本颜色固定为白色,只需在自定义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>
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
1036 次 |
| 最近记录: |