【问题标题】:SplashScreen not full screen when exist on Android < 12在 Android < 12 上存在时,SplashScreen 不是全屏
【发布时间】:2021-12-14 08:44:23
【问题描述】:

我有带有白色状态栏和导航栏的应用程序。我已经定义了这样的 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>

MainActivity

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

【问题讨论】:

    标签: android android-splashscreen


    【解决方案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>
    

    【讨论】:

    • 我正在使用androidx.core:core-splashscreen:1.0.0-alpha02 版本。我会尝试将其降级为 alpha01
    • @Linh 如果你使用支持库,可能是主题问题。你不需要降级
    • 貌似是库的问题,降级到alpha01后就不会出现这个问题,但是又出现了一个问题:(。(SplashScreen上的应用图标看起来比alpha01版本小
    • @Linh,最后,这很好,但很奇怪。图标小,因为你没有把它放在正确的文件夹里,试着改变它。
    • 实际上,我使用矢量可绘制图标,所以我不认为它来自可绘制文件夹。相同的设备尺寸,但在 Android 12 版本上,它看起来更大
    【解决方案2】:

    试试这个:

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

    把它写在你的onCreate 方法中。更多信息,Read this

    【讨论】:

    • 谢谢,但还是同样的问题。我已经尝试过标志 FLAG_FULLSCREEN 或 setDecorFitsSystemWindows
    • 创建一个新的 SplashActivity,并在其中尝试。你的代码似乎有问题。因为这应该可行。
    • 另外,请检查这是否不是特定于设备的问题。
    • 它发生在我的主应用程序上,我创建了一个演示(所有代码都在问题内)。我只是在三星 A51 (Android 11) 上测试,还是和 Android 8 一样的问题
    猜你喜欢
    • 2021-08-11
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    相关资源
    最近更新 更多