在 AlertDialog 中,我可以设置 Message 的大小,但是当我对 Title 执行相同操作时,它会崩溃。
代码:
AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message).setTitle(title)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
TextView titleTxt= (TextView)dialog.findViewById(android.R.id.title);
**titleTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);** // crash here
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
**textView.setTextSize(40);** // works fine
Button btn1 = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
btn1.setTextSize(36);
我的输出:
05-10 11:49:56.917: E/AndroidRuntime(8376): FATAL EXCEPTION: main
05-10 11:49:56.917: E/AndroidRuntime(8376): java.lang.NullPointerException
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.binary.taxitop.LoginScreen.showAlertDialog(LoginScreen.java:116)
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.binary.taxitop.LoginScreen.VerifyCredentialsAndEnterNextScreen(LoginScreen.java:103)
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.binary.taxitop.LoginScreen.onClick(LoginScreen.java:84)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.view.View.performClick(View.java:3511)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.view.View$PerformClick.run(View.java:14109)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.os.Handler.handleCallback(Handler.java:605)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.os.Handler.dispatchMessage(Handler.java:92)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.os.Looper.loop(Looper.java:137)
05-10 11:49:56.917: E/AndroidRuntime(8376): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-10 11:49:56.917: E/AndroidRuntime(8376): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 11:49:56.917: E/AndroidRuntime(8376): at java.lang.reflect.Method.invoke(Method.java:511)
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-10 11:49:56.917: E/AndroidRuntime(8376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-10 11:49:56.917: E/AndroidRuntime(8376): at dalvik.system.NativeStart.main(Native Method)
提前致谢。