如何修复我的整个PhoneGap应用程序的屏幕方向

问题描述:

如何将Phonegap应用程序配置为仅修复肖像模式,我有可能使用CSS或JavaScript来完成此操作,以便我能够获得一致的行为跨平台如何修复我的整个PhoneGap应用程序的屏幕方向

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

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

是否有可能通过CSS3媒体查询?

要解决在纵向模式中将方向只需添加下面一行在你的活动代码在AndroidManifest.xml文件:

android:screenOrientation="portrait" 

或这项活动中类:

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
+0

我不想做只机器人,没有任何独立于平台的方法 –

+0

则u必须在类文件逻辑设定的方向。 –

+0

请您详细说明如何操作,请相应修改您的答案,谢谢您的回复。 –

其实你可以使用config.xml将其设置为所有设备如果您使用PhoneGap Build ...
设置属性:方向可能值默认景观,或肖像
例如:

<偏好NAME = “方向” 值= “风景”/>

*请注意:该默认意味着横向和纵向均启用。

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

+4

确实如此,文档说明了这一点,但它从来没有用Android的方式工作,只有Android清单配置。 –

+3

真的,不工作的android –

+1

我认为这就是如果你只使用Phonegap构建哪一个是独立的呢? – hallodom

使用此代码在您的清单

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

我有android:screenOrientation="portrait"更新<path to phonegap app>/platform/android/AndroidManifest.xml。设置为默认,横向或纵向。

请参阅以下一个完整的例子:

 <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>