I want to run my app in portrait mode, I'm aware this isn't best practice but there are reasons to do this. and while I have disabled the rotation it still is able to rotate on some views will it doesn't on others.
I have this part of code in my Android Manifest:
<activity
android:name="<name>.app.MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|keyboard|locale|orientation"
android:screenOrientation="portrait">
I'm using fragments to show different containers depending on user input.
this is the only activity that has fragments. I have tried a few solutions on this site. including setting portrait mode on by code
On the main screen of Rotation Manager, select an orientation by tapping on either the vertical or horizontal icons next to a specific app to lock it into either landscape or portrait mode. Highlighting both icons will allow that particular app to auto-rotate.
If you want to develop an application in portrait mode, add screenOrientation inside application tag. In the above result it is showing only portrait mode. now turn your device it not going to change the view according to orientation.
You just have to define the property below inside the activity element in your AndroidManifest. xml file. It will restrict your orientation to portrait. Additionaly, as per Eduard Luca's comment below, you can also use screenOrientation="sensorPortrait" if you want to enable rotation by 180 degrees.
You can do it something like below.
After rootView in your java add this line
getActivity().setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // programmatically
For example:
View rootView = inflater.inflate(R.layout.activityxml, container, false);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
And also in your manifest change it:
android:configChanges="orientation|keyboardHidden"
as
android:configChanges="keyboardHidden"
<activity
android:name="com.test.activity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden" >
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