我正在尝试为使用AlertDialogPro构建的对话框设置自定义字体,但是在尝试使用检索对话框Button时却得到了NPE dialog.getButton(int)
。以及如何设置消息的字体和对话框的标题?
AlertDialogPro.Builder builder = new AlertDialogPro.Builder(this);
builder.setMessage(getResources().getString(R.string.dialog_body))
.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do stuff
}
});
AlertDialogPro dialog = builder.create();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTypeface(customTf));
dialog.show();
日志:
03-02 16:30:22.982: E/AndroidRuntime(15596):
java.lang.NullPointerException: Attempt to invoke virtual method 'void android
.widget.Button.setTypeface(android.graphics.Typeface)' on a null
object reference
通过做两件事来修复它:
代码:
AlertDialogPro.Builder builder = new AlertDialogPro.Builder(this);
builder.setMessage(getResources().getString(R.string.dialog_body))
.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do stuff
}
});
AlertDialogPro dialog = builder.create();
dialog.show();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTypeface(customTf));
((TextView) dialog.findViewById(R.id.adp_message)).setTypeface(customTf);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句