我通过添加“super.setIntegerProperty(”splashscreen“,R.drawable.splash)在我的phonegap应用程序中添加了一个启动画面;”在DefaultActivity中的super.loadURL ...行之前的行。
是否有办法在不锁定整个应用程序的情况下仅将启动画面的方向锁定为纵向?
答案 0 :(得分:5)
以下解决方案适用于Android和iOS上的Cordova 3+。它仅锁定启动画面的方向,然后在应用程序运行时将其解锁。
在config.xml中修复方向:
<preference name="orientation" value="portrait" />
然后在应用初始化后使用此screen orientation plugin解锁:
document.addEventListener("deviceready", function(){
screen.unlockOrientation();
}, false);
答案 1 :(得分:4)
经过多次搜索,我发现解决启动屏幕方向的正确方法是使用此代码管理两张图片到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");
}
答案 2 :(得分: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>
答案 3 :(得分:0)
在splashscreen活动的onCreate方法中写下以下内容:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
答案 4 :(得分:0)
在AndroidManifest.xml中添加以下行:
<activity android:name="SplashScreen" android:screenOrientation="portrait"></activity>