更改android 5.0以下版本上alertDialog的标题颜色
我创建了一个更改android 5.0以下版本上alertDialog的标题颜色,android,android-alertdialog,android-dialog,Android,Android Alertdialog,Android Dialog,我创建了一个AlertDialog,想更改AlertDialog的标题颜色,但每次尝试都失败了。它在安卓5.0及以上版本上运行得非常好,标题颜色为黑色,但在安卓5.0以下运行时,标题颜色变为白色,我使用了style和互联网上的许多其他来源,但失败了,我的代码如下: AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(msg) .setCancelabl
AlertDialog
,想更改AlertDialog的标题颜色,但每次尝试都失败了。它在安卓5.0及以上版本上运行得非常好,标题颜色为黑色,但在安卓5.0以下运行时,标题颜色变为白色,我使用了style和互联网上的许多其他来源,但失败了,我的代码如下:
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();
我的问题通过以下方式得到解决:
dialog.setTitle( Html.fromHtml("<font color='#FF7F27'>Set IP Address</font>"))
dialog.setTitle(Html.fromHtml(“设置IP地址”))
但我不想用这个,任何帮助都将不胜感激。您可以在此查看“我的对话框”的屏幕截图。使用自定义主题自定义警报对话框
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();
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>
@颜色/md_青色900
@颜色/白色
@颜色/原色\u深色
使用自定义主题自定义警报对话框
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();
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>
@颜色/md_青色900
@颜色/白色
@颜色/原色\u深色
使用创建自定义视图并在对话框中设置
setContentView(此处的自定义视图) 使用创建自定义视图并在对话框中设置 setContentView(此处的自定义视图) 第一类
AlertDialog.Builder builder = new AlertDialog.Builder(this,
然后键入
android.R.style.Theme_DeviceDefault_Dialo
然后Crtl+空间,然后你会得到一些建议。你可以这样选择
AlertDialog.Builder builder = new AlertDialog.Builder(this,
android.R.style.Theme_DeviceDefault_Dialog);
或
或
或
或
等等。第一类
AlertDialog.Builder builder = new AlertDialog.Builder(this,
然后键入
android.R.style.Theme_DeviceDefault_Dialo
然后Crtl+空间,然后你会得到一些建议。你可以这样选择
AlertDialog.Builder builder = new AlertDialog.Builder(this,
android.R.style.Theme_DeviceDefault_Dialog);
或
或
或
或
等等。创建自定义xml并将其设置在dialogint PlateId=dialog.getContext().getResources().getIdentifier(“android:id/alertTitle”,null,null)上;TextView title=(TextView)dialog.findViewById(平板);title.setTextColor(…如果这有帮助?@Dhina,no mate它不工作title为null是吗?创建自定义xml并在dialogint PlateId=dialog.getContext().getResources().getIdentifier(“android:id/alertTitle”,null,null);TextView title=(TextView)dialog.findViewById(PlateId);title.setTextColor(…如果这有帮助?@Dhina,no mate它不起作用标题为空是吗?请确保您正在使用support Lib中的“AlertDialog”。它应该起作用。是的,它是,这是我的导入文件,导入android.support.v7.app.AlertDialog;我需要一个对话框,因为我正在通过编程为该对话框设置一个角半径,所以,我不能使用它。请确保e如果您正在使用AppCompat主题扩展AppCompat活动,那么它应该可以工作。:)请确保您正在使用support Lib中的“AlertDialog”。它应该可以工作。是的,它是,这是我的导入文件,导入android.support.v7.app.AlertDialog;我需要一个对话框,因为我正在通过编程方式为该对话框设置角半径,因此,我不能使用itLet us。请确保您正在使用AppCompat主题扩展AppCompative。然后它应该d工作:)