Android. Lock orientation of screen for all Activities [duplicate]

荒凉一梦 提交于 2019-12-19 05:18:58

问题


Possible Duplicate:
How can I set Orientation Fixed for all activities

I would like to lock my screen orientation for my app. I mean that all Activities must have the same landscape orientation. I don't want to add android:screenOrientation="portrait" in the manifest for all activities. Is there any other way? thanks Regards


回答1:


You have two options for achieving the result.

  • You can specify per activity base orientation requirement in manifest file. You can select here what orientation you want to support for which activity.

e.g.

<activity
    android:name=".Some_Act"
    android:label="@string/app_name"
    android:screenOrientation="portrait" >
</activity>
  • You can create a base activity and specify the orientation in that activity. Later you can inherit that activity in other activities of your application. You can choose suitable base class to get the desired behavior.



回答2:


android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation"

Add the above lines in your app's manifest for all the activities .



来源:https://stackoverflow.com/questions/12859836/android-lock-orientation-of-screen-for-all-activities

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