【问题标题】:Android 12 Splash Screen API not working with Material ComponentAndroid 12 Splash Screen API 不适用于 Material 组件
【发布时间】:2022-08-04 00:03:13
【问题描述】:

我一直在关注文档,但不幸的是它不包括使用 Material Component 作为应用整体主题时的适配。

<style name=\"Theme.App\" parent=\"Theme.MaterialComponents.DayNight\">
    <!-- Primary brand color. -->
    <item name=\"colorPrimary\">@color/colorPrimary</item>
    <item name=\"colorPrimaryVariant\">@color/colorPrimaryDark</item>
    <item name=\"colorOnPrimary\">@android:color/white</item>
    <!-- Secondary brand color. -->
    <item name=\"colorSecondary\">@color/colorPrimary</item> <!--Fab color-->
    <item name=\"colorOnSecondary\">@color/colorAccent</item> <!--Fab icon color-->
    <item name=\"colorSecondaryVariant\">@color/colorAccentDark</item>
    <!-- Status bar color. -->
    <item name=\"android:statusBarColor\">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
    <!--<item name=\"tabStyle\">@style/AppTabLayout</item>-->
    <!-- The color for all other text including the menu -->
    <item name=\"android:textColor\">@color/colorPrimary</item>
    <item name=\"android:textColorHighlight\">@color/colorAccentDark</item>
    <item name=\"android:windowAnimationStyle\">@style/WindowAnimationTransition</item>

    <item name=\"checkboxStyle\">@style/AppCheckBoxStyle</item>
    <item name=\"popupMenuBackground\">@drawable/popup_bg_rounded</item>
    <item name=\"materialAlertDialogTheme\">@style/AppDialogTheme</item>

    <item name=\"autoCompleteTextViewStyle\">@style/AppCursor</item>

    <item name=\"overlapAnchor\">false</item>
    <item name=\"android:dropDownVerticalOffset\">?attr/actionBarSize</item>

    <item name=\"android:forceDarkAllowed\" tools:targetApi=\"q\">false</item>
</style>

<style name=\"Theme.App.Starting\" parent=\"Theme.SplashScreen\">
        <item name=\"windowSplashScreenBackground\">
            @color/whitePrimaryDark
        </item>
        <item name=\"postSplashScreenTheme\">
            @style/Theme.Cryptonian.NoActionBar
        </item>
    </style>

安卓清单

    <activity
        android:name=\".presentation.MainActivity\"
        android:exported=\"true\"
        android:screenOrientation=\"portrait\"
        android:theme=\"@style/Theme.App.Starting\"
        android:windowSoftInputMode=\"adjustPan\">
        <intent-filter>
            <action android:name=\"android.intent.action.MAIN\" />

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

它因错误而崩溃

  Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).

有没有人面临同样的问题?

标签: android material-components-android android-12 android-splashscreen


【解决方案1】:

你需要改变这个:

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

对此:

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

postSplashScreenTheme 需要获取您的应用主题。显示启动画面后,您的应用主题将显示

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-27
    • 2022-12-02
    • 1970-01-01
    • 2021-10-24
    • 2020-09-29
    • 1970-01-01
    • 2023-01-03
    • 2021-07-27
    相关资源
    最近更新 更多