imagine your activity is (forced!) in portrait mode and you'll show an dialog from there, but in landscape mode (because it's containing view is larger than screen width), how will you do that?
I think the screen-orientation of a dialog depends on it's hosting activity/service.
Is there still a way? (e.g. force default orientation of dialog view over it's layout xml-file?)
When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.
I think the easiest way in the latest Android versions is by going to Design mode of an XML (not Text). Then from the menu, select option - Create Landscape Variation. This will create a landscape xml without any hassle in a few seconds.
If you are under DialogFragment
Use
on dialog create getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
and on dialog dissmiss getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if you don't want activity recreate add also
android:configChanges="orientation|screenSize"
other way you will have to handle activity being recreated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With