2013-04-04 52 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