user1480734
user1480734

Reputation: 141

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

Upvotes: 9

Views: 4865

Answers (1)

Pedro Teran
Pedro Teran

Reputation: 1200

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

Upvotes: 4

Related Questions