簡體   English   中英

強制Phonegap(Android)啟動畫面方向

[英]Force Phonegap(Android) splash screen orientation

我通過添加“super.setIntegerProperty(”splashscreen“,R.drawable.splash)在我的phonegap應用程序中添加了一個啟動畫面;” 在DefaultActivity中的super.loadURL ...行之前的行。

有沒有辦法只將鎖定屏幕的方向鎖定到縱向而不鎖定整個應用程序?

以下解決方案適用於Android和iOS上的Cordova 3+。 它僅鎖定啟動屏幕的方向,然后在應用程序運行時將其解鎖。

修復config.xml中的方向:

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

然后使用此屏幕方向插件在應用初始化后將其解鎖:

document.addEventListener("deviceready", function(){
    screen.unlockOrientation();
}, false);

經過多次搜索后,我發現解決啟動屏幕方向的正確方法是使用此代碼管理兩個圖像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");
    }

如果您使用的是最新版本的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>

在splashscreen活動的onCreate方法中寫下以下內容:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

在AndroidManifest.xml中添加以下行:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM