简体   繁体   English

科尔多瓦方向锁定垂直翻转不起作用

[英]cordova orientation lock vertical flip not working

I am trying to lock orientation for cordova android app to landscape using 我正在尝试使用以下方法将cordova android应用程序的方向锁定为横向

<preference name="Orientation" value="landscape" />

This works fine it loads app in landscape view. 在横向视图中加载应用程序效果很好。 But when I flip the emulator vertically(upside down - 180degree) the screen remains fixed and does flips the view vertically. 但是,当我垂直翻转模拟器(上下-180度)时,屏幕保持固定,并且确实垂直翻转了视图。 I want to show in landscape mode only even if user rotates the device to 180 degrees. 我只想即使用户将设备旋转180度也才能以横向模式显示。

Using cordova-android: 7.0.0 使用cordova-android:7.0.0

Any suggestions? 有什么建议么?

I have found a solution to this, without using any plugin. 我找到了一个解决方案,没有使用任何插件。 We can put configuration in config.xml to modify AndroidManifest.xml at build time. 我们可以将配置放在config.xml中,以便在构建时修改AndroidManifest.xml。

Put the following in config.xml 将以下内容放在config.xml中

<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="merge">
   <activity android:name="MainActivity" android:screenOrientation="userLandscape" />
</edit-config>

Also add following in the <widget> tag of config.xml 还要在config.xml的<widget>标记中添加以下内容

xmlns:android="schemas.android.com/apk/res/android"

Following are possible values for the screenOrientation field 以下是screenOrientation字段的可能值

screenOrientation (attr) enum [behind=3, fullSensor=10, fullUser=13,
landscape=0, locked=14, nosensor=5, portrait=1, reverseLandscape=8, 
reversePortrait=9, sensor=4, sensorLandscape=6, sensorPortrait=7, 
unspecified=4294967295, user=2, userLandscape=11, userPortrait=12]

Please use this for unlock(both mode) for 请将此用于解锁(两种模式)

 screen.orientation.unlock();

and use screen lock portrait mode 并使用屏幕锁定纵向模式

screen.orientation.lock('portrait');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM