<style name="DialogTheme" parent="ThemeOverlay.AppCompat.Dialog">
<item name="android:textColorPrimary">your color here</item>
</style>
接着,在创建对话框时,不要使用AlertDialog.Builder(Context)
构造函数,而是使用AlertDialog.Builder(Context, int)
方法,并传递一个指向你的样式的引用:
new AlertDialog.Builder(this, R.style.DialogTheme)
.setTitle("Hello world")
.setMessage("some longer text for the body of the dialog")
.show();
尽管这取决于更改textColorPrimary
,但它不会以影响应用程序中其他任何内容的方式进行。bottomBright
、topDark
和topBright
。 - Raheel Hasanandroid.app.AlertDialog
还是支持库版本的 android.support.v7.app.AlertDialog
? - Ben P.简单来说,您只需要使用以下代码更改“TITLE”文本:
Html.fromHtml("<font color='#FFFFFF'>TITLE</font>")
此代码将完全根据您添加的颜色值更改文本颜色。您也可以将其用于按钮的文本。
SpannableString title = new SpannableString("Your title");
title.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.your_color)), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
然后将其作为标题传递
new AlertDialogBuilder(context).setTitle(title).show();
用相同的方式处理消息。
试试这个,
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(Html.fromHtml("<font color='#0288D1'>This is a test</font>"));
builder.setPositiveButton(Html.fromHtml("<font color='#0288D1'>Yes</font>"), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
Log.e(LOG_TAG, "Yes");
}
});
builder.setNegativeButton(Html.fromHtml("<font color='#0288D1'>No</font>"), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
Log.e(LOG_TAG, "No");
}
});
builder.create();
builder.show();