Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
强制Phonegap(Android)启动屏幕方向_Android_Cordova - Fatal编程技术网

强制Phonegap(Android)启动屏幕方向

强制Phonegap(Android)启动屏幕方向,android,cordova,Android,Cordova,我通过在super.loadURL之前添加“super.setIntegerProperty”(“splashscreen”,R.drawable.splash);”行,在我的phonegap应用程序中添加了一个启动屏幕。。。DefaultActivity中的行 有没有一种方法可以只将启动屏幕的方向锁定为纵向,而不锁定整个应用程序?在启动屏幕活动的onCreate方法中写入以下内容: setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATIO

我通过在super.loadURL之前添加“super.setIntegerProperty”(“splashscreen”,R.drawable.splash);”行,在我的phonegap应用程序中添加了一个启动屏幕。。。DefaultActivity中的行


有没有一种方法可以只将启动屏幕的方向锁定为纵向,而不锁定整个应用程序?

在启动屏幕活动的onCreate方法中写入以下内容:


setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向)

在AndroidManifest.xml中添加此行:

<activity android:name="SplashScreen" android:screenOrientation="portrait"></activity> 

如果您使用的是最新版本的PhoneGap(DroidGap)或Apache Cordova,您可以通过在Android.xml文件中更改屏幕方向来强制将屏幕方向设置为横向。生成的DroidGap“实例化活动”应如下所示:

        <activity 
        android:name="org.apache.cordova.DroidGap" 
        android:label="@string/app_name" 
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="landscape"           
        > 
        <intent-filter> 
        </intent-filter> 
    </activity>

经过多次搜索,我发现解决启动屏幕方向问题的正确方法是在
main活动中使用此代码管理两个图像

 if (getResources().getConfiguration().orientation == 2) {
        super.setIntegerProperty("splashscreen", R.drawable.splashlandscape);
        Log.d("Orientation", "Landscape");
    }
    else {
        super.setIntegerProperty("splashscreen", R.drawable.splashportrait);
        Log.d("Orientation", "Portrait");
    }

以下解决方案适用于Android和iOS上的Cordova 3+。它只锁定splashscreen的方向,然后在应用程序运行时解锁

修复config.xml中的方向:

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

谢谢,但问题是,对于Phonegap,splashscreen不是一个单独的活动。如果我将方向强制到该活动,我将强制整个应用程序。这不会将整个应用程序的方向锁定到横向吗?最初的问题是关于将启动屏幕方向锁定为纵向,而不锁定整个应用程序的方向。谢谢!工作起来很有魅力!
document.addEventListener("deviceready", function(){
    screen.unlockOrientation();
}, false);