How to disable landscape mode?

2019-06-10 19:41发布

i'n my application i have Fragment's in a viewPager i know how to disable the landscape from manifest and from java like :

            android:configChanges="orientation"
           android:screenOrientation="portrait"

////////////////////////////////
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    (setContent.....)

but if i hold my device in landscape mode and then i running the application the application load in landscape and the portarti mode not working. why is that?

Ok i figure it out my bad:

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);

I forget to delete this line

2条回答
萌系小妹纸
2楼-- · 2019-06-10 20:13

In the AndroidManifest.xml file add this android:screenOrientation="portrait"

to all the activities !! Thats all !!

查看更多
男人必须洒脱
3楼-- · 2019-06-10 20:14

android:screenOrientation="landscape" is one side landscpe

android:screenOrientation="sensorLandscape" is both side landscape

android:screenOrientation="portrait" is one side portrait

android:screenOrientation="sensorPortrait" is both side portrait

android:screenOrientation="fullSensor" is all 4 sides

android:screenOrientation="sensor" is one side landscape and one side potrate

查看更多
登录 后发表回答