AlertDialog和DialogPreference

时间:2011-11-14 11:42:26

标签: android dialog preferences android-dialog android-gui

我有这个用于我的警告对话框,这很完美

 ContextThemeWrapper ctw = new ContextThemeWrapper( MvcnContactList.this, R.style.MyTheme );
                alertDialogBuilder = new AlertDialog.Builder(ctw);
//set some views and onclick listeners
                alertDialog = alertDialogBuilder.create();
                alertDialog.setCancelable(false);
                alertDialog.show();

但是我有一个关于首选项的对话框,我希望这个对话框具有与我的警报对话框相同的方框。但我不知道将这种风格应用到我的对话框

public class About extends DialogPreference {
    public AboutDialog(Context oContext, AttributeSet attrs)
    {
        super(oContext, attrs); 
    }
}

注意:我在我的pref.xml文件中放了android:style =“@ style / impex_dialog”,这个样式标记无法识别。

1 个答案:

答案 0 :(得分:0)

警报对话框使用:

com.android.internal.R.style.Theme_Dialog_Alert

来自Android来源:

protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
    super(context, com.android.internal.R.style.Theme_Dialog_Alert);
    setCancelable(cancelable);
    setOnCancelListener(cancelListener);
    mAlert = new AlertController(context, this, getWindow());
}

所以我想你应该尝试这样的事情,因为它在themes.xml中定义:

<!-- Default theme for alert dialog windows, which is used by the
        {@link android.app.AlertDialog} class.  This is basically a dialog
         but sets the background to empty so it can do two-tone backgrounds. -->
<style name="Theme.Dialog.Alert" parent="@android:style/Theme.Dialog">
    <item name="windowBackground">@android:color/transparent</item>
    <item name="windowTitleStyle">@android:style/DialogWindowTitle</item>
    <item name="windowIsFloating">true</item>
    <item name="windowContentOverlay">@null</item>
</style>