【问题标题】:Splash Screen API not support in Dark mode暗模式下不支持闪屏 API
【发布时间】:2022-03-30 19:18:10
【问题描述】:

我正在尝试实现启动画面。

我已经按照闪屏 API 方法实现了 implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'

splash.xml

<style name="Theme.App.Start" parent="Theme.SplashScreen">
  <item name="windowSplashScreenBackground">#FFF</item>
  <item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_baby_changing_station_24</item>
  <item name="postSplashScreenTheme">@style/Theme.SplashScreenApi</item>
</style>

splash.xml(用于暗模式)

<style name="Theme.App.Start" parent="Theme.SplashScreen">
   <item name="windowSplashScreenBackground">#3A3A3A</item>
   <item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_baby_changing_station_24</item>
   <item name="postSplashScreenTheme">@style/Theme.SplashScreenApi</item>
</style>

Manifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.App.Start">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:theme="@style/Theme.App.Start">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

MainActivity.kt

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        installSplashScreen()

        setContentView(R.layout.activity_main)
    }
}

深色模式下仍然显示黑色图标

在光照模式下完美工作

设备名称:小米红米 Note 7 Pro,
Android 版本:Android 10 (SDK 29)

【问题讨论】:

  • 你尝试过其他一些图标吗?
  • @SujalKumar 是的,我也试过了。
  • 你试过 beta01 吗?
  • @VadimCaen 我试过了。但仍然无法正常工作。先生,您能分享在其他设备上正常工作的任何启动画面 api 项目吗?谢谢。

标签: android splash-screen android-12


【解决方案1】:

改变这个:

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

到这里:

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

(其中 AppTheme 是您的主题名称)

此外,无需在活动和应用程序中应用 Splash 主题。所以我建议你在 application 标签中改变它:

android:theme="@style/Theme.App.Start"

到这里:

android:theme="@style/AppTheme"

【讨论】:

  • 其实Theme.SplashScreenApi是我的主旋律。我更改了应用程序标签主题但无法正常工作。显示相同的问题。
  • 你试过用普通的drawables代替vector one吗?
  • 是但和以前一样
【解决方案2】:

基本上,我得到了作为背景颜色和启动器图标的飞溅

我也遇到了同样的问题,跟着我的步骤走

首先,创建 values-v31(在这个 values-v31 文件夹中添加相同的 Theam 和样式文件)和 values-night-v31(在这个 values-night-v31 文件夹中添加相同的 Theam 和样式文件)。

不要使用

   <style name="Theme.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/black</item>
    <item name="android:windowBackground">@drawable/your_logo</item>
    <item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>

用这个

 <style name="Theme.MySplash" parent="Theme.SplashScreen.Common">
    <item name="windowSplashScreenBackground">@color/black</item>
    <item name="android:windowBackground">@drawable/your_logo</item>
    <item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>

【讨论】:

    【解决方案3】:

    将库版本更新为 "androidx.core:core-splashscreen:1.0.0-beta02"。效果很好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-21
      • 2020-02-29
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-08
      • 2020-07-27
      相关资源
      最近更新 更多