【问题标题】:cordova orientation lock vertical flip not working科尔多瓦方向锁垂直翻转不起作用
【发布时间】:2019-01-21 09:57:39
【问题描述】:

我正在尝试将 cordova android 应用程序的方向锁定为横向使用

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

这很好,它可以在横向视图中加载应用程序。但是当我垂直翻转模拟器(倒置 - 180 度)时,屏幕保持固定并垂直翻转视图。即使用户将设备旋转 180 度,我也只想以横向模式显示。

使用cordova-android:7.0.0

有什么建议吗?

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    我找到了解决方案,无需使用任何插件。我们可以在 config.xml 中进行配置,以便在构建时修改 AndroidManifest.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>
    

    同时在 config.xml 的 &lt;widget&gt; 标签中添加以下内容

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

    以下是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]
    

    【讨论】:

      【解决方案2】:

      请使用此解锁(两种模式)

       screen.orientation.unlock();
      

      并使用屏幕锁定纵向模式

      screen.orientation.lock('portrait');
      

      【讨论】:

      • 是的,需要插件
      • 好的。实际上,我不想为此功能使用单独的插件。我的回答解决了没有任何插件的问题。
      • 这个答案在应用启动时也不起作用,所以如果你有启动画面,它可能是颠倒的。
      猜你喜欢
      • 2017-04-26
      • 1970-01-01
      • 2017-09-20
      • 2016-08-18
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      相关资源
      最近更新 更多