嗨,我在SO中搜索了此类错误,但找不到解决方案,为什么在onResume()方法中创建自定义对话框时触发了requestFeature()错误。
我正在调用dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);在像这样设置contentview之前,请执行以下操作: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();
}
最佳答案
试试下面的代码:-
final Dialog dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.myxml);