【发布时间】: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