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?)
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
Related
I have an Activity that has android:screenOrientation="portrait" options set in AndroidManifest.xml.
At all times, I want this Activity to stay in portrait mode.
However, one of the buttons opens a dialog that has SignaturePad widget, provided by this library.
Because user has to sign with their finger/stylus, I want to make the Dialog landscape so there is more space to sign.
Is it possible to change Dialog's orientation without changing the Activity's orientation?
I've tried DialogFragment, system level dialog (TYPE_SYSTEM_ALERT) and few other things. Nothing seems to work.
I have a custom AlertDialog which is opened by a button click. I have made two xml layouts for it. Normal portrait layout and landscape which I put into res/layout-land folder. When dialog is opened, I change the screen orientation and it won't refresh to apply respective xml layout. But if I open the dialog after I changed orientation, correct xml will be inflated.
I have tried with and without this line in my AndroidManifest.xml,
android:configChanges="orientation|screenSize"
and without it, it is even worse. Dialog gets closed and the keyboard is opened. I don't know what is going on there. One way would be to reopen dialog by hand, but I don't know how to do that either. I'm starting a dialog on a button click inside fragment's onCreateView. Other than that, I don't have any other method set up regarding AlertDialog.
Thanks in advance!
I have an activity, let's call it HomeActivity, whose screenOrientation has been set to landscape in the manifest file.
Clicking on a button in the HomeActivity presents a Dialog Activity which floats over HomeActivity.
There is a portrait version and a landscape version for the layout that is to be displayed in this dialog, but for this scenario, only the portrait version should be displayed.
In the onCreate() method of the Dialog Activity, I've requested Portrait Orientation but this causes both the dialog and the HomeActivity behind to rotate to portrait mode. I do not want this.
Is there a way to set the orientation of the top most activity without affecting the orientation of the "behind" activity?
Thanks for your help?
Orientation is system-wide property so it can only be landscape or portrait at the one time. This includes all displayed activities (including dialog), status bar and buttons.
You have to display HomeActivity and Dialog Activity with the same orientation.
Also, forcing Activity orientation in the manifest is a bad practice in general.
I have one activity which i am using as host for calling all my fragments.I am using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) for setting screen in landscape mode.But problem is that it is making every fragment in landscape mode because their is only one parent activity for all of them.I can not use android:screenOrientation="landscape" because this will also work the same.
I want one of my fragment to be displayed always in landscape mode and remaining fragment as according to device orientation.Is their is another ways for doing it?
If you wanna show one specific Fragment in landscape you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
in the onCreate() of your Fragment.
In this Fragments onPause() f.e. you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
which is the default value and enables screen rotation changes.
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?
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.
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).