I have an Android app which has a main activity and 3 Fragments which are tabs. I would like the application to remain in portrait mode at all times but I can't seem to get this working. This is what I have tried, as per another stack overflow post, but I'm not sure what I'm doing wrong....does it need to be different if using fragments?
<activity
android:name="com.tutorial.test.activities.act1"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Thank you!!
Edit: The ViewPager is on the FragmentActivity for which I am setting the screenOrientation as above.
Try this..
You can try with programmatically.
After rootView
in your java add this line getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
For Ex:
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.tutorial.test.activities.act1"
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