如何更改单选按钮的颜色?下图显示默认情况下单选按钮为蓝色,但我想更改此内容。
我的代码是:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setCustomTitle(promptsView);
alertDialogBuilder.setItems(frequencyName, null);
// alertDialogBuilder.setTitle("SELECT FREQUENCY");
alertDialogBuilder.setSingleChoiceItems(frequencyName, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
selectedFre = frequencyName[i];
}
});
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
txtFrequency.setText(selectedFre);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
答案 0 :(得分:2)
为AlertDialog
<style name="MaterialThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/action_bar_background</item>
</style>
使用该样式创建AlertDialog.Builder
,如下例所示。
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
getActivity(),
R.style.MaterialThemeDialog);
alertDialogBuilder.setTitle(R.string.image_resolution);
alertDialogBuilder.setSingleChoiceItems(R.array.quality_labels, getPosition(), this);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();