繁体   English   中英

如何更改Android AlertDialog选择的背景色

[英]How to change the Android AlertDialog selection background color

在此处输入图片说明

我在android中使用“警报对话框”,我需要在更改颜色的同时选择我该怎么做?

如果您检查图像第二行“右”被选中但不正确可见,所以我想将其更改为较深的颜色。

    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");

如果要更改background色,请尝试:

 AlertDialog dialog = builder.create();

 dialog.show();

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));

希望这可以帮助

尝试这个:

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>

参见下面的样式代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM