2013-04-04 87 views
1

我的源AlertDialog主題不工作

private static final int ALERT_DIALOG = 1; 

    @Override 
    public void onBackPressed() { 
     // buildAlertMessageExit(); 

     showDialog(ALERT_DIALOG); 
    } 

    @Override 
    protected Dialog onCreateDialog(int id) { 
     Dialog dialog = null; 
     if (id == ALERT_DIALOG) { 
      ContextThemeWrapper ctw = new ContextThemeWrapper(this, 
        R.style.AlertDialogCustom); 
      AlertDialog.Builder builder = new AlertDialog.Builder(ctw); 
      builder.setMessage("Hello World") 
        .setTitle("Alert Dialog") 
        .setIcon(android.R.drawable.ic_dialog_alert) 
        .setCancelable(false) 
        .setPositiveButton("Close", 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, 
             int which) { 
            dialog.dismiss(); 
           } 
          }); 
      dialog = builder.create(); 
     } 
     if (dialog == null) { 
      dialog = super.onCreateDialog(id); 
     } 
     return dialog; 
    } 

styles.xml

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog"> 
    <item name="android:windowBackground">@null</item> 
    <item name="android:windowFrame">@null</item> 
    </style> 

,結果沒有主題

enter image description here

+0

你想要透明背景嗎?然後嘗試'@ color/transparent'。 – Tushar 2013-04-04 07:23:02

+0

你想要什麼.. ?? – 2013-04-04 08:56:01

+0

@Dhaval Sodha Parmar - 我想與主題 – 2013-04-04 10:54:45

回答

4

insted的這個:

ContextThemeWrapper ctw = new ContextThemeWrapper(this, 
        R.style.AlertDialogCustom); 
      AlertDialog.Builder builder = new AlertDialog.Builder(ctw); 

嘗試

AlertDialog.Builder builder = new AlertDialog.Builder(this, 
       R.style.AlertDialogCustom_); 

But its require MIN API LEVEL 11.

如果你需要支持Android >= 3.0你可能要創建(使用AlertDialog代替custom dialog

檢查此link瞭解更多詳情。

+1

<3.0 ??的對話。你確定?僅供參考,[AlertDialog](http://developer.android.com/reference/android/app/AlertDialog.html)自API級別1起可用 – 2013-04-04 12:02:35

+1

@PareshMayani:正確讀取:但其需要MIN API級別11而不是API 1。 – 2013-04-04 12:06:46