2013-08-30 95 views
0

我試圖在我的應用程序中自定義AlertDialogs。應用AlertDialog樣式

當涉及到應用的風格,我的應用程序崩潰

我只應用背景顏色,像這樣......

<style name="fd_dialog" parent="@android:style/Theme.Dialog"> 
    <item name="android:background">#FFFFFF</item> 
</style> 

和Java代碼...

public void quit(View v) 
{ 
    AlertDialog.Builder confirm = new AlertDialog.Builder(this, R.style.fd_dialog); 
    confirm.setTitle("Quit?"); 
    confirm.setIcon(R.drawable.questionicon); 
    confirm.setMessage("Are You Sure You Want To Log Out?"); 
    confirm.setPositiveButton("Quit", new DialogInterface.OnClickListener() 
    { 
     @Override 
     public void onClick(DialogInterface dialog, int which) 
     { 
      //do some stuff here 
     } 
    }); 
    confirm.setNegativeButton("Cancel", null); 
    confirm.show(); 
} 

我在做什麼錯了?

編輯:這是按要求的logcat:

08-30 15:25:27.349: W/dalvikvm(2020): threadid=1: thread exiting with uncaught exception (group=0x40018578) 

08-30 15:25:27.359: E/AndroidRuntime(2020): FATAL EXCEPTION: main 

08-30 15:25:27.359: E/AndroidRuntime(2020): java.lang.IllegalStateException: Could not execute method of the activity 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.view.View$1.onClick(View.java:2144) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.view.View.performClick(View.java:2485) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.view.View$PerformClick.run(View.java:9080) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.os.Handler.handleCallback(Handler.java:587) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.os.Handler.dispatchMessage(Handler.java:92) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.os.Looper.loop(Looper.java:130) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.app.ActivityThread.main(ActivityThread.java:3687) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at java.lang.reflect.Method.invokeNative(Native Method) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at java.lang.reflect.Method.invoke(Method.java:507) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at dalvik.system.NativeStart.main(Native Method) 
08-30 15:25:27.359: E/AndroidRuntime(2020): Caused by: java.lang.reflect.InvocationTargetException 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at java.lang.reflect.Method.invokeNative(Native Method) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at java.lang.reflect.Method.invoke(Method.java:507) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at android.view.View$1.onClick(View.java:2139) 

08-30 15:25:27.359: E/AndroidRuntime(2020):  ... 11 more 

08-30 15:25:27.359: E/AndroidRuntime(2020): Caused by: java.lang.NoSuchMethodError: android.app.AlertDialog$Builder.<init> 

08-30 15:25:27.359: E/AndroidRuntime(2020):  at com.firsthosted.firstdroid.Home.quit(Home.java:537) 

8-30 15:25:27.359: E/AndroidRuntime(2020): ... 14 more 
+0

post logCat .... –

+0

@codeMagic你是指從XML或onClickListener的android:onClick?它從xml –

+0

調用,在第537行是我發佈的java代碼 –

回答

0

,你可以嘗試這個::

AlertDialog.Builder建設者=新AlertDialog.Builder(新ContextThemeWrapper(這一點,R.style.fd_dialog));

0

檢查這是否有所幫助。而不是

AlertDialog.Builder confirm = new AlertDialog.Builder(This,R.style.fd_dialog);使用這個

AlertDialog.Builder confirm = new AlertDialog.Builder(youractivity.this,R.style.fd_dialog);

+0

只是試過這個...沒有運氣 –

+0

有一個它的構造函數http://developer.android.com/reference/android/app/AlertDialog.Builder.html#AlertDialog.Builder(android.content.Context,int) – codeMagic

+0

對不起,我的錯 – Ritaban