How to set application fragments to portrait mode only?

放肆的年华 提交于 2019-12-01 10:47:55

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" >

Orientation attribute is per activity so you can declare the orientation for only the activity that contains the fragment so that it is in landscape and the rest of the activities will remain as they are.

getActivity().setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

or you can declare in the manifest

<activity android:name=".Control" android:screenOrientation="portrait"></activity>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!