我如何解决“您需要在此活动中使用 Theme.AppCompat 主题(或后代)”的问题Android 12 中的问题

发布于 2025-01-15 14:22:16 字数 68 浏览 0 评论 0原文

我如何解决“您需要在此活动中使用 Theme.AppCompat 主题(或后代)”问题。

安卓12问题...

How I resolved the “You need to use a Theme.AppCompat theme (or descendant) with this activity” Issue.

Android 12 issue...

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

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

发布评论

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

评论(2

月野兔 2025-01-22 14:22:17

我在迁移到新的 SplashScreen API 时遇到了同样的错误。对我来说,在调用 super.onCreate() 之前在启动活动中调用 installSplashScreen() 很有帮助。

文档: https://developer.android.com/guide/主题/ui/splash-screen/migrate#migrate_your_splash_screen_implementation

I've faced the same error while migrating to the new SplashScreen API. For me, it was helpful to call installSplashScreen() in the starting activity before calling super.onCreate().

Documentation: https://developer.android.com/guide/topics/ui/splash-screen/migrate#migrate_your_splash_screen_implementation

古镇旧梦 2025-01-22 14:22:16

步骤:-1 添加此主题。

<resources xmlns:tools="http://schemas.android.com/tools">
        <!-- Base application theme. -->
        <style name="Theme.Android_12_Splash_Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
            <!-- Primary brand color. -->
            <item name="colorPrimary">@color/purple_500</item>
            <item name="colorPrimaryVariant">@color/purple_700</item>
            <item name="colorOnPrimary">@color/white</item>
            <!-- Secondary brand color. -->
            <item name="colorSecondary">@color/teal_200</item>
            <item name="colorSecondaryVariant">@color/teal_700</item>
            <item name="colorOnSecondary">@color/black</item>
            <!-- Status bar color. -->
            <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
            <!-- Customize your theme here. -->
            <item name="windowSplashScreenBackground">@color/white</item>
            <item name="windowSplashScreenAnimatedIcon">@drawable/ic_camera_edit</item>
            <item name="windowSplashScreenAnimationDuration">300</item>
            <item name="postSplashScreenTheme">@style/Theme.Android_12_Splash_Demo</item>
            <item name="android:navigationBarColor">@color/black</item>
    
            <!-- This is used for status bar hide and show-->
            <item name="android:windowLightStatusBar">false</item>
    
            <!-- This use bottom brand image -->
            <item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ic_camera_edit</item>
    
        </style>
    
    </resources>

步骤:- 2 将此主题分配给清单中的应用程序

<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.Android_12_Splash_Demo">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name=".DashboardActivity"
            android:exported="false" />
        <activity
            android:name=".LoginActivity"
            android:exported="false" />

    </application>

Step:-1 Add this theme.

<resources xmlns:tools="http://schemas.android.com/tools">
        <!-- Base application theme. -->
        <style name="Theme.Android_12_Splash_Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
            <!-- Primary brand color. -->
            <item name="colorPrimary">@color/purple_500</item>
            <item name="colorPrimaryVariant">@color/purple_700</item>
            <item name="colorOnPrimary">@color/white</item>
            <!-- Secondary brand color. -->
            <item name="colorSecondary">@color/teal_200</item>
            <item name="colorSecondaryVariant">@color/teal_700</item>
            <item name="colorOnSecondary">@color/black</item>
            <!-- Status bar color. -->
            <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
            <!-- Customize your theme here. -->
            <item name="windowSplashScreenBackground">@color/white</item>
            <item name="windowSplashScreenAnimatedIcon">@drawable/ic_camera_edit</item>
            <item name="windowSplashScreenAnimationDuration">300</item>
            <item name="postSplashScreenTheme">@style/Theme.Android_12_Splash_Demo</item>
            <item name="android:navigationBarColor">@color/black</item>
    
            <!-- This is used for status bar hide and show-->
            <item name="android:windowLightStatusBar">false</item>
    
            <!-- This use bottom brand image -->
            <item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ic_camera_edit</item>
    
        </style>
    
    </resources>

Step:- 2 assign this theme to application in manifest

<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.Android_12_Splash_Demo">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name=".DashboardActivity"
            android:exported="false" />
        <activity
            android:name=".LoginActivity"
            android:exported="false" />

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