PhoneGap/Android - 将方向锁定为纵向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23909428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PhoneGap/Android - Locking orientation to portrait
提问by user3089184
I have tried every method to lock the screen to portrait orientation but they simply do not work after testing the app via Adobe PhoneGap Build.
我尝试了各种方法将屏幕锁定为纵向,但在通过 Adobe PhoneGap Build 测试应用程序后,它们根本不起作用。
Firstly, I have modified the MainActivity.java file to include at onCreate
首先,我修改了 MainActivity.java 文件以包含在 onCreate
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Secondly, I have modified the config.xml file to include
其次,我修改了 config.xml 文件以包含
<preference name="orientation" value="portrait" />
Thirdly, I have modified the Manifest file to include
第三,我修改了清单文件以包含
android:screenOrientation="portrait"
None of the above are working.
以上都不起作用。
回答by user3094755
Update the config.xml File which is in your project folder, above www.
更新位于 www 上方的项目文件夹中的 config.xml 文件。
Add the line:-
添加行:-
<preference name="orientation" value="portrait" />
Then build you project & there will be no Orientation Change.
然后构建你的项目 & 不会有方向改变。
In place of "portrait" you can use "landscape".
代替“肖像”,您可以使用“风景”。
回答by magicode118
If you're using Cordova 3.4.1 <preference name="orientation" value="portrait" />
should work.
如果您使用 Cordova 3.4.1<preference name="orientation" value="portrait" />
应该可以工作。
Also, don't forget to add: android:configChanges="orientation"
in the activity tag.
另外,不要忘记android:configChanges="orientation"
在活动标签中添加:。
Else, you can try using this plugin: https://github.com/cogitor/PhoneGap-OrientationLock
否则,您可以尝试使用此插件:https: //github.com/cogitor/PhoneGap-OrientationLock
回答by Adarsh Nahar
just put below in activity tag below application tag in android manifest.xml file
只需将其放在 android manifest.xml 文件中应用程序标签下方的活动标签中
android:screenOrientation="portrait"
Thanks
谢谢