AppCompat style dialog containing fragment

I need a dialogue in the style of AppCompat - background, name, button position, button hue, etc. - containing the fragment.

Using custom DialogFragment onCreateDialog() you can return AppCompatDialog , and then you can expand the new layout in onCreateView() , and childFragmentManager can replace childFragmentManager to replace the look of the replacement fragment. But as a result, the dialog is otherwise an empty box without buttons. They can be added manually to the dialog box layout, but they do not get style from AppCompat.

The same applies if you increase the target fragment of DialogFragment .

To get the AppCompat buttons, you can use AlertDialog.Builder and use .setView() to set the layout, but then I cannot find a way to set the fragment as content. If you try childFragmentManager.beginTransaction().replace() from onCreateDialog() , you will get:

  java.lang.IllegalStateException: Fragment does not have a view 

It seems that even after using builder.setView() or dialog.create() , then dialog.setView() , onCreateView() and getView() always return null.

The second answer here seems to cover this in quite some detail, but it does not offer a favorable solution: https://stackoverflow.com/a/316618/

If you override onCreateView() or getView() to return the View that you overestimated, you will get:

  android.util.AndroidRuntimeException: Window feature must be requested before adding content at android.support.v7.app.AppCompatDelegateImplV7.throwFeatureRequestIfSubDecorInstalled(AppCompatDelegateImplV7.java:1479) 
+5
source share

All Articles