Reputation: 853
Is there a way to showing a dialog always in portrait? I need that because of its layout.
I know that I can set that for an Activity with
android:screenOrientation="portrait|reversePortrait"
But what about a dialog?
Upvotes: 0
Views: 2246
Reputation: 1619
Not sure these ways will fit your requirement ,
One way is showing Activity as a dialog with screen orientation set to portrait (with dialog theme)
refer DialogActivity
from ApiDemos
Other way is forcing activity to change its orientation by
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
and open dialog in onConfigurationChanged()
(with some logic).
Upvotes: 1
Reputation: 7585
At the time of the dialog showing, check the device's orientation.
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getOrientation();
//if orientation is portrait then show, if not then don't.
Upvotes: 2