【问题标题】:How to fix screen orientation to portrait for my whole PhoneGap app如何为我的整个 PhoneGap 应用程序将屏幕方向固定为纵向
【发布时间】:2011-09-20 09:00:25
【问题描述】:

如何将 Phonegap 应用程序配置为仅固定为纵向模式,我有可能使用 CSS 或 JavaScript 来完成,这样我应该能够获得跨平台的一致行为

我发现这篇有用的帖子detecting-displays-orientation-change-on-mobile-devices-with-accelerometer-a-platform-indipendent-approach

这里解释了如何检测方向,但我需要配置它

是否可以通过 CSS3 媒体查询?

【问题讨论】:

    标签: iphone android cordova screen-orientation


    【解决方案1】:

    要在纵向模式下修复您的方向,只需在 AndroidManifest.xml 文件的活动标签中添加以下行:

     android:screenOrientation="portrait"
    

    或者活动类中的这个:

    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    【讨论】:

    • 我不想只为Android做,有没有任何平台无关的方法
    • 那么你必须在你的类文件中逻辑地设置方向。
    • 能否请您详细说明如何操作,请相应修改您的答案,谢谢您的回复。
    • 感谢您的回复。我有同样的问题,在 phonegap 文档中找不到。你能指出这方面的任何文档吗?
    • @Maulik J 谢谢,这对我很有帮助!
    【解决方案2】:

    实际上你可以使用 config.xml 将其设置为所有设备如果你使用的是 PhoneGap Build...
    设置属性:orientation,可能的值为 defaultlandscapeportrait 示例:

    *请注意,默认意味着启用横向和纵向。

    来源:
    https://build.phonegap.com/docs/config-xml

    【讨论】:

    • 确实如此,文档上这么说,但它从来没有对我有用,只有 Android 清单配置。
    • 我认为那是如果你只使用单独的 Phonegap 构建?
    • 对我也不起作用...这是最好的解决方案,因为如果我更改清单,我会在再次构建 phonegap 应用程序后丢失它。
    • 使用版本 Cordova 4.0.0..,我在我的 cofig.XML 文件中修复/放置了这一行。它适用于Android。应用程序运行值=“纵向”或“横向”模式单独。它正在工作的命令行方法
    【解决方案3】:

    在清单中使用此代码

    <activity android:name=".DroidGap" 
    android:label="@string/app_name"
    android:screenOrientation="landscape" > 
    

    【讨论】:

      【解决方案4】:

      我必须将&lt;path to phonegap app&gt;/platform/android/AndroidManifest.xml 更新为android:screenOrientation="portrait"。设置为默认、横向或纵向。

      完整示例见下文:

           <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="HelloWorld" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
              <intent-filter>
      
                  <action android:name="android.intent.action.MAIN" />
      
                  <category android:name="android.intent.category.LAUNCHER" />
      
              </intent-filter>
      
          </activity>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多