androidkotlinandroid-fragmentsandroid-dialogfragmentandroid-orientation

How do I allow only one specific fragment to have both portrait and landscape orientations in Android?


In my Android application, I have added android:screenOrientation="portrait" to all activities in my Android.manifest and android:orientation="vertical" to every activity's/fragment's respective layout so that the app can only be viewed in portrait mode.

However, there is one fragment in particular that I want to enable both portrait and landscape orientations. This fragment extends the DialogFragment() class as it's a full-screen fragment. This fragment is contained within another fragment, so it uses childFragmentManager to be displayed.

How do I enable both portrait and landscape orientations for a specific fragment, while only enabling portrait orientation for the rest of my activities and fragments?


Solution

  • You can try this answer: https://stackoverflow.com/a/53864286/15351040

    Just change the rotation type to Sensor or User, and reset when the fragment is destroyed or paused.