我在android中使用Alert Dialog,我需要更改背景颜色,同时选择我该怎么做?
如果你检查图像第二行“右”被选中但是没有正确显示,所以我想把它改成更深的颜色。
android.app.AlertDialog.Builder builderSingle = new android.app.AlertDialog.Builder(ModeActivity.this);
builderSingle.setTitle("Select Part");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
ABIModeActivity.this,
android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("1");
arrayAdapter.add("2");
arrayAdapter.add("3");
答案 0 :(得分:1)
如果您想更改background
颜色,请尝试:
AlertDialog dialog = builder.create();
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
希望这有帮助
答案 1 :(得分:1)
试试这个:
AlertDialog.Builder builderSingle = new AlertDialog.Builder(ModeActivity.this, R.style.Your_App_theme);
并在style.xml中添加主题:
<style name="Your_App_theme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorControlNormal">@color/colorPrimary</item>
<item name="colorControlActivated">@color/colorPrimary</item>
<item name="colorControlHighlight">@color/colorPrimary</item>
</style>
答案 2 :(得分:0)
见下面的代码代码:
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@color/myColor</item>
</style>
现在这种风格适用于对话框:
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)