Android:Dialog和onResume()方法中的requestWindowFeature错误

时间:2014-12-31 05:58:44

标签: android dialog onresume

您好我搜索了SO以查找此类错误但无法找到解决方案为什么在onResume()方法中创建自定义对话框时触发此requestFeature()错误的原因。

我在设置内容视图之前调用 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); ,如此 dialog.setContentView(R.layout.fav_info_dialog);

以下是我的代码

@Override
protected void onResume() {
    super.onResume();

    supportInvalidateOptionsMenu();
    ActivityCompat.invalidateOptionsMenu(Converter.this);
    // update the title
    updateTheTittle(getResources().getString(R.string.menu_units));
    cancleBtn.setVisibility(View.GONE);
    //
    if (mSharedPref.getInt(Constants.HOME_INFO_DIALOG_STATUS, 0) == 0)
        if (mSharedPref.getInt(Constants.DASHOBOARD_TYPE,
                Constants.GridView) == 2)
            createCustomDialog();
}

private void createCustomDialog() {

    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.fav_info_dialog);

    dialog.setCanceledOnTouchOutside(true);

    Button button = (Button) dialog.findViewById(R.id.desc_ok);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SharedPreferences mSharedPref = getSharedPreferences(
                    Constants.PREFERENCE_FILENAME, Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor = mSharedPref.edit();
            editor.putInt(Constants.HOME_INFO_DIALOG_STATUS, 1);
            editor.commit();
            dialog.dismiss();
        }
    });
    dialog.show();
}

1 个答案:

答案 0 :(得分:2)

尝试以下代码: -

final Dialog dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.myxml);