我曾试图通过使用下面这个函数来改变AlertDialog的字体
private void saveDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(res.getString(R.string.dialog_title))
.setMessage(res.getString(R.string.dialog_saveconfirm))
.setCancelable(false)
.setNegativeButton(res.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setPositiveButton(res.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do some thing
});
AlertDialog alert = builder.create();
alert.show();
TextView tit = (TextView) alert.findViewById(android.R.id.title);
TextView msg = (TextView) alert.findViewById(android.R.id.message);
Button btn2 = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
Button btn1 = alert.getButton(DialogInterface.BUTTON_POSITIVE);
tit.setTypeface(UtiliShare.getTf());
msg.setTypeface(UtiliShare.getTf());
btn1.setTypeface(UtiliShare.getTf());
btn2.setTypeface(UtiliShare.getTf());
}
当我在Activity中调用函数时,当设置字体类型时,
tit
出现了02-25 17:59:04.759: E/AndroidRuntime(1014): java.lang.NullPointerException
,但是当我删除tit
时,对话框工作良好。我认为错误出现在
TextView tit = (TextView) alert.findViewById(android.R.id.title);
,它返回null。我该如何解决这个问题?? 更新: 此链接包含了我的问题的答案:答案 感谢Sam。
alertTitle
代替title
来改变AlertDialog的字体大小:Changing font size into an AlertDialog。(我自己没有尝试过。) - Sam