I am trying to use new dialogs with materials with fragments in AppCompat v22.1. According to Chris Banes , for this:
Just return new AppCompatDialog(getActivity(), getTheme()) from onCreateDialog(Bundle) .
Setting this parameter:
public class MyFragment extends DialogFragment { public MyFragment() { } public Dialog onCreateDialog(Bundle savedInstanceState) { return new AppCompatDialog(getActivity(), getTheme()); } ... }
works fine in the normal case; the dialogue is correctly designed and that’s it. However, when we try to show a dialog with the STYLE_NO_TITLE parameter:
MyFragment fragment = new MyFragment(); fragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0); fragment.show(getSupportFragmentManager(), "DIALOG");
it raises the following exception and failure:
05-19 12:18:38.806 15458-15458/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.test.testdialog, PID: 15458 android.util.AndroidRuntimeException: requestFeature() must be called before adding content at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:302) at android.app.Dialog.requestWindowFeature(Dialog.java:1066) at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:317) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I think the problem might be with DialogFragment calling requestWindowFeature() instead of supportRequestWindowFeature() (?)
Is there any workaround?
source share