我需要在 CustomAlertDialog 上设置 alpha Button
。我试过这个:
AlertDialog userdialog = new AlertDialog.Builder(mActivity)
.create();
userdialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton) {
// Snippet: Do sth.
return;
}
});
userdialog.getButton(AlertDialog.BUTTON_POSITIVE).getBackground().setAlpha(100);
但我得到这个错误:
07-18 08:57:43.831: E/AndroidRuntime(4955): FATAL EXCEPTION: main
07-18 08:57:43.831: E/AndroidRuntime(4955): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ttet.tsquare.pure/com.ttet.tsquare.pure.Map}: java.lang.NullPointerException
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.os.Looper.loop(Looper.java:123)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-18 08:57:43.831: E/AndroidRuntime(4955): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 08:57:43.831: E/AndroidRuntime(4955): at java.lang.reflect.Method.invoke(Method.java:521)
07-18 08:57:43.831: E/AndroidRuntime(4955): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
07-18 08:57:43.831: E/AndroidRuntime(4955): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
07-18 08:57:43.831: E/AndroidRuntime(4955): at dalvik.system.NativeStart.main(Native Method)
07-18 08:57:43.831: E/AndroidRuntime(4955): Caused by: java.lang.NullPointerException
07-18 08:57:43.831: E/AndroidRuntime(4955): at com.ttet.tsquare.pure.Dialog.show(Dialog.java:160)
07-18 08:57:43.831: E/AndroidRuntime(4955): at com.ttet.tsquare.pure.Map.onCreate(Map.java:63)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-18 08:57:43.831: E/AndroidRuntime(4955): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-18 08:57:43.831: E/AndroidRuntime(4955):
... 11 more
怎么了?我该怎么办?