How to fix screen orientation to portrait for my whole PhoneGap app

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-31 18:58:51

问题


How to configure the Phonegap app to be fixed to only portrait mode, I there any possibility to do it with CSS or JavaScript so that I should be able to get the consistent behaviour across the platforms

I found this useful post detecting-displays-orientation-change-on-mobile-devices-with-accelerometer-a-platform-indipendent-approach

Here it is explained how to detect the orientation, but I need to configure it

Is it possible through CSS3 Media queries?


回答1:


To fix your orientation in portrait mode just add the below line in your activity tag in AndroidManifest.xml file:

 android:screenOrientation="portrait"

or this in the activity class:

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);



回答2:


Actually you can use config.xml to set it to all devices if you're using PhoneGap Build...
Set the propertie: orientation with possible values default, landscape, or portrait
example:

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

*please note that default means both landscape and portrait are enabled.

Source:
https://build.phonegap.com/docs/config-xml




回答3:


use this code in your manifest

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



回答4:


I had to update <path to phonegap app>/platform/android/AndroidManifest.xml with android:screenOrientation="portrait". Set to default, landscape, or portrait.

See below for a full example:

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


来源:https://stackoverflow.com/questions/7482600/how-to-fix-screen-orientation-to-portrait-for-my-whole-phonegap-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!