Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applying splash give me error You need to use a Theme.AppCompat theme (or descendant) with this activity

in 23 we have these styles define by default now i have to start splash with full screen

vlue/stylefile

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

v21style file:

 <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

manifest:

 android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".User_MainInterface"
            android:label="@string/title_activity_user__main_interface"
            android:theme="@style/AppTheme.AppBarOverlay"></activity>

please help me to solve this problem quickly

like image 905
Hamees Arshad Avatar asked Nov 25 '25 04:11

Hamees Arshad


2 Answers

If you are experiencing this error when implementing the new SplashScreen API for Android 12, don't forget to installSplashScreen:

SplashScreen splashScreen = SplashScreen.installSplashScreen(this);

Don't forget to add this before setContentView().

like image 84
meow2x Avatar answered Nov 27 '25 20:11

meow2x


In case is useful for anyone.

if you are using androidx.core:core-splashscreen and this error comes out, for me, using kotlin, what worked was:

calling installSplashScreen() before super.onCreate(savedInstanceState) in the onCreate method.

Importing import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen

it should look similar to:

override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        //other methods
}
like image 30
Marcos Avatar answered Nov 27 '25 21:11

Marcos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!