Android 12 Splash Screen API不使用材料组件

发布于 2025-01-18 15:21:50 字数 2926 浏览 0 评论 0原文

我一直在关注文档,但不幸的是它不包括使用材质组件作为应用程序整体主题时的适应。

<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>

Android Manifest

    <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).

有人面临同样的问题吗?

I've been following the documentation, but unfortunately it doesn't include the adaptation when using Material Component as app overall theme.

<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>

Android Manifest

    <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>

It crash with an error

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

Does anyone face same issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

德意的啸 2025-01-25 15:21:50

解决方案是在调用 super.onCreate()setContentView 之前安装 Splash Screen API

The solution is to install the Splash Screen API before calling super.onCreate() and setContentView

说不完的你爱 2025-01-25 15:21:50

您需要将其更改

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

为:

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

postSplashScreenTheme 需要获取应用程序主题。显示启动画面后您的应用程序主题 wi

You need to change this:

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

to this:

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

postSplashScreenTheme requires to get you app theme. after showing splash screen your app theme wi

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文