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

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

Android 12 issue...



Solution 1:[1]

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>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nil Sinojiya