在android 5.0下面更改alertDialog的标题颜色

Rep*_*tor 1 android android-alertdialog android-dialog

我创建了一个AlertDialog并且想要更改AlertDialog的标题颜色但是在每次尝试中都失败了.它的工作原理很细上Android 5.0与标题颜色和上面为黑色,但是当它运行下面的是Android 5.0,它的标题颜色获取的变成白色,我用了风格和许多其他来源来自互联网但失败了,我的代码如下,

AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(msg)
            .setCancelable(true)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });

    final AppCompatDialog dialog = builder.create();
    dialog.setTitle("VALIDATION_TITLE error");
    dialog.setCancelable(false);
    dialog.show();
Run Code Online (Sandbox Code Playgroud)

我的问题通过以下方式得到解决,

dialog.setTitle( Html.fromHtml("<font color='#FF7F27'>Set IP Address</font>"))
Run Code Online (Sandbox Code Playgroud)

但我不想用这个,任何帮助都会非常感激.您可以通过此聊天链接查看我的对话框的屏幕截图

Dar*_*ish 5

使用自定义主题自定义警报对话框

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle);
builder.setTitle("My Dialog");
builder.setMessage(msg)
                .setCancelable(true)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
       final AppCompatDialog dialog = builder.create();
       dialog.show();
Run Code Online (Sandbox Code Playgroud)

styles.xml - 自定义样式

<style name="MyAlertDialogMaterialStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <!-- Used for the buttons -->
        <item name="colorAccent">@color/md_teal_900</item>
        <!-- Used for the title and text -->
        <item name="android:textColorPrimary">@color/white</item>
        <!-- Used for the background -->
        <item name="android:background">@color/color_primary_dark</item>
    </style>
Run Code Online (Sandbox Code Playgroud)