0

我有带有白色状态栏和导航栏的应用程序。我已经定义了这样的 Splash 主题。

<style name="Theme.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#00f</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_play_arrow_24</item>
    <item name="windowSplashScreenAnimationDuration">200</item>

    <item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>

<style name="Theme.AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:statusBarColor">#fff</item>
    <item name="android:navigationBarColor">#fff</item>
</style>

主要活动

class MainActivity : AppCompatActivity() {

    var keepSplashScreen = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val splashScreen = installSplashScreen()

        splashScreen.setOnExitAnimationListener { splashScreenProvider ->
            val fadeAnim = ObjectAnimator.ofFloat(
                splashScreenProvider.view, View.ALPHA, 1f, 0f
            )
            fadeAnim.duration = 4000L
            fadeAnim.interpolator = AccelerateInterpolator()
            fadeAnim.doOnEnd { splashScreenProvider.remove() }
            fadeAnim.start()
        }
        splashScreen.setKeepVisibleCondition { keepSplashScreen }
        setContentView(R.layout.activity_main)

        Handler(Looper.getMainLooper()).postDelayed({
            keepSplashScreen = false
        }, 3000)
    }
}

SplashTheme在设备 Android 12 (Pixel 4XL) 上运行良好,但在 Android 8 (Xiomi A2)上运行SplashTheme时,它不会显示全屏。

在此处输入图像描述

从这个视频中,当SplashScreen开始存在(淡入淡出动画)时,会显示白色状态栏和导航栏(在 Android 12 上,SplashScreen存在时始终全屏)。如何SplashScreen在 Android < 12 上始终全屏显示?

4

2 回答 2

1

我认为问题可能是您不使用紧凑型库。如果您不使用支持库,则启动画面在较低版本中的外观与以前完全相同。

implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'

SplashScreen 实际上使用包含图像视图的框架布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">

  <ImageView
      android:id="@+id/splashscreen_icon_view"
      android:layout_width="?attr/splashScreenIconSize"
      android:layout_height="?attr/splashScreenIconSize"
      android:layout_gravity="center"/>

</FrameLayout>
于 2021-12-14T09:19:27.030 回答
0

尝试这个:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

把它写在你的onCreate方法里面。有关更多信息,请阅读此内容。

于 2021-12-14T08:47:00.943 回答