How to prevent a Phonegap application to switch to landscape view

倖福魔咒の 提交于 2019-12-21 03:16:08

问题


This one should be very simple, however it's not. I'm trying to prevent my application from going into landscape view so I've changed the config.xml file like this: <preference name="orientation" value="portrait" />. Unfortunately, it's not working. Any ideas?


回答1:


Ok, so I got it: The reason Phonegap ignored the <preference name="orientation" value="portrait" /> in the config.xml file is because my app was in debug mode. once I created a release version it stopped from going to landscape.




回答2:


hello you can install this plugin https://github.com/gbenvenuti/cordova-plugin-screen-orientation

and add this function on you index.js or one of your first executed js document

window.addEventListener("orientationchange", function(){
    screen.lockOrientation('portrait');
});

thank u




回答3:


Small piece of code and here you go. Try it.

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



回答4:


For platform android just set prefered orientation in androidManifest.xml like this

 <activity
        android:name="com.payoda.Insurance.SplashScreenActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar"
    >
    </activity>

For IOS the following link may help you

Force portrait orientation on iPhone with phonegap



来源:https://stackoverflow.com/questions/23673892/how-to-prevent-a-phonegap-application-to-switch-to-landscape-view

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