【问题标题】:Android 12 Spash API crashes on launchAndroid 12 Spash API 在启动时崩溃
【发布时间】:2021-12-24 16:32:10
【问题描述】:

Gradle

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

然后是 styles.xml。请注意,图标和背景渐变在 Android Studio 侧边槽中渲染得很好。

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@drawable/background_gradient</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_logo_svg</item>
    <item name="postSplashScreenTheme">@style/Theme.AppNative</item>
</style>

在我的 AndroidManifest.xml 中,我设置了起始主题

<application
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/APP_NAME"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.App.Starting">

    <activity
        android:name="com.myapp.android.feature.FeatureActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

然后在Activity中,我安装启动画面

@ExperimentalAnimationApi
@ExperimentalMaterialApi
@AndroidEntryPoint
class FeatureActivity : ComponentActivity() {

    val viewModel: FeatureViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        installSplashScreen()
        AppCenter.hydrate(application)
        setContent {
            CustomTheme {
                CompositionLocalProvider(
                    LocalCoilImageLoader provides viewModel.imageLoader)
                {
                    FeatureScreen()
                }
            }
        }
    }
}

应用程序崩溃

原因:android.content.res.Resources$NotFoundException: Drawable com.myapp.android.debug:drawable/compat_splash_screen_no_icon_background 资源 ID #0x7f070064 原因:android.content.res.Resources$NotFoundException: Can't find ColorStateList from drawable resource ID #0x7f0700af

【问题讨论】:

    标签: android android-jetpack android-12


    【解决方案1】:
     <item name="windowSplashScreenBackground">@drawable/background_gradient</item>
    

    此行正在创建错误。背景必须是颜色值,不支持可绘制对象(至少目前是这样)。您可以查看docs中的示例

    工作示例:

    <item name="windowSplashScreenBackground">@color/colorPrimary</item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多