强制Phonegap(Android)启动画面方向

use*_*804 5 android cordova

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

有没有办法只将锁定屏幕的方向锁定到纵向而不锁定整个应用程序?

Mar*_*iry 5

经过多次搜索,我发现解决闪屏方向的正确方法是使用此代码将两个图像管理到您的MainActivity

 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");
    }
Run Code Online (Sandbox Code Playgroud)


Lan*_*and 1

如果您使用的是最新版本的 PhoneGap (DroidGap) 或 Apache Cordova,您可以通过更改 Android.xml 文件中的 screenOrientation 来强制屏幕方向为横向。生成的 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>
Run Code Online (Sandbox Code Playgroud)

  • 这不会将整个应用程序的方向锁定为横向吗?最初的问题是关于将启动屏幕方向锁定为纵向,而不锁定整个应用程序的方向。 (7认同)