PhoneGap/Android - 锁定纵向方向

use*_*184 21 android screen orientation cordova

我已经尝试了将屏幕锁定为纵向的每种方法,但是在通过Adobe PhoneGap Build测试应用程序后它们根本无法工作.

首先,我修改了MainActivity.java文件以包含在onCreate中

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Run Code Online (Sandbox Code Playgroud)

其次,我修改了config.xml文件以包含

<preference name="orientation" value="portrait" />
Run Code Online (Sandbox Code Playgroud)

第三,我修改了Manifest文件以包含

android:screenOrientation="portrait"
Run Code Online (Sandbox Code Playgroud)

以上都不起作用.

use*_*755 26

更新项目文件夹中的config.xml文件,位于www.

添加行: -

<preference name="orientation" value="portrait" />
Run Code Online (Sandbox Code Playgroud)

然后构建您的项目,将不会有方向更改.

代替"肖像",您可以使用"风景".


zal*_*517 22

如果你使用Cordova 3.4.1 <preference name="orientation" value="portrait" />应该工作.

另外,不要忘记android:configChanges="orientation"在activity标记中添加:.

否则,您可以尝试使用此插件:https://github.com/cogitor/PhoneGap-OrientationLock

  • 嘿@ zalow517,你引用的"活动标签"是什么?(添加`android:configChanges ="orientation"`) (9认同)