【发布时间】:2013-12-01 07:00:43
【问题描述】:
我想在如下图所示的对话框中更改按钮按下的颜色。
我在使用简单的警报对话框时设法做到了这一点。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Set dialog title
builder.setTitle(Html.fromHtml("<font color='#8b0000'>"
+ getResources().getString(R.string.delete_this_list)
+ "?" + "</font>"));
builder.setMessage(getResources().getString(R.string.delete)
+ " '"
+ lists[listNo]
+ "'?\n"
+ getResources().getString(
R.string.delete_this_list_description))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.delete),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
//Some background stuff
//.......//
}
})
.setNegativeButton(
getResources().getString(android.R.string.cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alertDialog = builder.create();
alertDialog.show();
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE)
.setBackground(getResources().getDrawable(R.drawable.btn_bar_holo_red));
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
.setBackground(getResources().getDrawable(R.drawable.btn_bar_holo_red));
但是,这种方法在使用 DialogFragments 时不起作用。 使用DialogFragments时,没有getButton方法。
有什么想法吗??
【问题讨论】:
-
你知道AlertDialog会在点击按钮后关闭对话框吗?
-
是的,我知道......我的意思是上面的代码适用于 AlertDialog,但不适用于对话框片段。由于 DialogFragment 返回一个 Dialog,我不能使用 getButton() 方法,因为该方法属于 AlertDialog。希望我清楚
-
屏幕截图中的标题颜色和标题分隔线实际上是如何改变的?
-
@Ewoks 在该项目中使用了 HoloEverywhere 库。然后要更改分隔线颜色,创建一个样式: ...然后在您的主题中添加上述样式:
-
@Ewoks 对于标题文本颜色,builder.setTitle(Html.fromHtml("对话框标题"));
标签: android android-alertdialog android-dialogfragment dialogfragment