Android disable landscape mode

跟風遠走 提交于 2020-01-13 16:23:10

问题


I wish to disable the landscape view in an android application . I've used :

 <activity android:name=".SomeActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">

It works but there is a slightly big problem . If I rotate the screen the activity restarts , and when it comes back , the screen is still in portrait mode . I want my app to completely ignore the device's position . There is no point in disabling the landscape view if when I rotate the device the activity restarts ( the screen becomes black for a few seconds , and then the activity appears again still in portrait mode ) .


回答1:


android:configChanges="orientation|keyboardHidden|keyboard"



回答2:


write a class and extend it to the activity. In that class add this code to a method. setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Then call this method to the activites to which you want to disable the landscape mode..



来源:https://stackoverflow.com/questions/7685163/android-disable-landscape-mode

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