Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force landscape mode for dialog?

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?)

like image 588
user1480734 Avatar asked Oct 02 '12 08:10

user1480734


People also ask

How do I force an app to open in landscape mode?

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.

How do I create a separate layout for landscape mode?

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.


1 Answers

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

like image 174
Pedro Teran Avatar answered Oct 06 '22 15:10

Pedro Teran