为什么 android 在 kitkat 和旧设备的横向模式下不显示启动画面?

why android splash screen is not showing in landscape orientation of kitkat & older devices?

我在我的 android 应用程序中添加了启动画面(具有 android API 级别 14-26 目标支持),如下所示:

在我的AndroidManifest.xml

<activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

在styles.xml中,SplashTheme定义为:

<style name="SplashTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">

        <item name="android:windowBackground">@drawable/splash_graphic</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

我的splash_graphic.xml如下:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/colorPrimary"/>
    </item>
    <item>
        <bitmap android:src="@drawable/my_logo" android:tileMode="disabled" android:gravity="center" />
    </item>
</layer-list>

我的 Splash Activity 为:

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startActivity(new Intent(SplashActivity.this, ActivationActivity.class));
        finish();
    }
}

我的奇怪问题是: 在 Lollipop 和更新的设备上,启动画面在横向和纵向屏幕方向上都可以正常工作,但它只适用于 Kitkat 和 pre-kitkat 设备上的纵向屏幕方向。我怎样才能让它在 kitkat 和 pre-kitkat 设备上也适用于横向?

尝试在javaclass

中使用
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

经过这么多小时的搜索,我终于找到了解决我的奇怪问题的方法,这不是编码解决方案。然而,这听起来有点尴尬, 我想分享它只是因为它对我有用,而且我认为它对其他人也有帮助。所以,这是我的解决方法:

原因:

This problem was being caused by the default home launcher app ,which manages apps showcasing in Landscape and Portrait screen orientation of devices [I observed the problem on 1. Huawei MediaPad T1 7.0 Tablet 2. Lenovo a-319 Rockstar and 3.Samsung Galaxy S Duos 7562 ]. But I did not observe any problem on any devices[Splash-screen worked on any screen orientations on 1. Samsung Galaxy J Max SM-T285YD Tab 2.Samsung J 7 Prime phone] that had Lollipop or newer android OSes.

解决方法:

So, I changed the default home launcher app on devices which had problem. EMUI launcher of Huawei MediaPad tab and Fly launcher of Lenovo a-319[I had rooted this device, so launcher is different than other Lenovo phones] were replaced with Google Now Launcher from google play, which now is not officially supported by google. As Samsung S Duos 7562 did not support Google Now Launcher, its TouchWiz launcher was replaced with Nova Launcher . After default home launcher app replacement, now, the problem is solved on all target devices.