无法更改AlertDialog项目的颜色

时间:2017-03-10 11:59:03

标签: java android alertdialog

我在不同的活动中创建了多个警报对话框。突然,AlertDialog项目突然显示为红色!

这是我的代码

AlertDialog.Builder builder = new AlertDialog.Builder(this, MyDialogStyle);
    builder.setTitle("Select Method :");
    final String[] choices = new String[]{"Weight Based", "Body Surface Area"};
    builder.setItems(choices, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // the user clicked on choice[which]
            switch (choices[which]) {
                case "Weight": {
                    create_item(false);
                    break;
                }
                case "Body Surface Area": {
                    create_item(true);
                    break;
                }
            }
        }
    });

    builder.show();

styles.xml(v21)

<style name="MyDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#000000</item>
    <item name="android:textColor">#000000</item>
    <item name="android:textColorPrimary">#000000</item>
    <item name="android:colorPrimary">#000000</item>
    <item name="android:colorAccent">#000000</item>
    <item name="android:textColorAlertDialogListItem">#000000</item>
    <item name="android:textColorSecondary">#000000</item>
    <item name="android:text">#000000</item>
    <item name="android:textAppearanceListItemSecondary">#000000</item>
    <item name="android:textAppearance">#000000</item>
    <item name="android:color">#000000</item>

styles.xml

<style name="MyDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#000000</item>
    <item name="android:textColor">#000000</item>
    <item name="android:textColorPrimary">#000000</item>\
    <item name="android:textColorAlertDialogListItem">#000000</item>
    <item name="android:textColorSecondary">#000000</item>
    <item name="android:text">#000000</item>
    <item name="android:textAppearance">#000000</item>
</style>

我尝试更改父样式或删除它,但两者都给出了相同的亮红色结果!任何想法?

1 个答案:

答案 0 :(得分:0)

尝试使用这种风格,,,希望它对你有用

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
    <item name="android:textColor">#00FF00</item>
    <item name="android:typeface">monospace</item>
    <item name="android:textSize">10sp</item>
</style>