Splash screen api is showing action bar for android 12
Asked Answered
D

6

10

After the splash screen loads, I am getting a action bar, but I have set postSplashScreenTheme to no action bar theme. This is happening only to android 12 emulator.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/white</item>

        <item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item>
        <item name="postSplashScreenTheme">@style/Theme.Design.NoActionBar</item>
        <item name="windowSplashScreenIconBackgroundColor">@color/blue</item>
        <item name="windowSplashScreenAnimationDuration">800</item>

        <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
    </style>
</resources>
Definition answered 23/3, 2022 at 9:20 Comment(2)
did you find a solution yet? @kunal-kalwarUniverse
Yes @MihodiLushan, now i am calling this actionBar?.hide() in my activity in on create.Definition
D
9

Don't forget to call actionBar?.hide() before installSplashScreen() to hide the action bar before the main view is displayed.

    actionBar?.hide()
    val installSplash= installSplashScreen()
Definition answered 13/6, 2022 at 7:6 Comment(1)
Doesn't work for meTruncate
G
12

Add the install function on your launcher activity

class MainActivity : Activity() {

   override fun onCreate(savedInstanceState: Bundle?) {
       installSplashScreen()

       super.onCreate(savedInstanceState)
       setContentView(R.layout.main_activity)

       ...

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

Gales answered 10/4, 2022 at 16:18 Comment(2)
Worked flawlessly!!Ovotestis
just a note for someone who is facing this issue and trying this solution, you must call if before setContent{......}Hollyanne
D
9

Don't forget to call actionBar?.hide() before installSplashScreen() to hide the action bar before the main view is displayed.

    actionBar?.hide()
    val installSplash= installSplashScreen()
Definition answered 13/6, 2022 at 7:6 Comment(1)
Doesn't work for meTruncate
S
1

Add this in your splash screen theme if you are using the Androidx SplashScreen compat library

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

Like:

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
   <!-- Set the splash screen background, animated icon, and animation duration. -->
   <item name="windowSplashScreenBackground">@color/...</item>

   <!-- Use windowSplashScreenAnimatedIcon to add either a drawable or an
        animated drawable. One of these is required. -->
   <item name="windowSplashScreenAnimatedIcon">@drawable/...</item>
   <!-- Required for animated icons -->
   <item name="windowSplashScreenAnimationDuration">200</item>

   <!-- Set the theme of the Activity that directly follows your splash screen. -->
   <!-- Required -->
   <item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
Sherrer answered 30/11, 2022 at 9:55 Comment(1)
This should be marked as correct, worked like a charmFreeload
K
1

It took me a day to fix this issue. Besides this issue, Android Studio cannot run the application on Android 12 and above. I had to run it manually. I found that the problem is caused by the emulator.

When I tested the application on the real device, I noticed that the AppBar did not appear. But I found another problem. On Android 9 device, SplashScreen doesnt appear, but works perfectly on Android 12 device with implementation 'androidx.core:core-splashscreen:1.0.0-beta02'.

This white bar shown only Emulator with AndroidVersion >= 12

Appbar still shown on the emulator but there is no problem on real device. Following implementation works both on all Android version.

Note: My app looks like the image above on Samsung A51. I'm investigating and trying to find a solution.

values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Theme for MainActivity and its fragments -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@color/black_transparent</item>
    </style>

    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">#ffffff</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/logo_splash</item>
        <item name="windowSplashScreenAnimationDuration">200</item>
        <item name="android:windowSplashScreenBehavior" tools:targetApi="tiramisu">@drawable/logo_splash</item>

        <!-- Set the theme of the Activity that directly follows your splash screen. -->
        <item name="postSplashScreenTheme">@style/AppTheme</item>
    </style>
</resources>

main/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
        <application
            android:name=".MyApplication"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/Theme.App.Starting">
    
            <activity
                android:name=".MainActivity"
                android:exported="true"
                android:launchMode="singleTop"
                android:theme="@style/Theme.App.Starting">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".OtherActivity"
                android:parentActivityName=".MainActivity"
                android:screenOrientation="portrait"
                android:theme="@style/AppTheme"/>
        </application>
</manifest>

MainActivity.java

public class MainActivity extends AppCompatActivity {
        protected void onCreate(Bundle savedInstanceState) {
            // Load things that should be loaded before rendering MainActivity.
            loadBeforeSplash();
    
            // Handle the splash screen transition.
            splashScreen = SplashScreen.installSplashScreen(this);
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // Other MainActivity stuffs
    }
}
Kelley answered 25/3, 2023 at 14:2 Comment(1)
Ohh yes lol, it was showing only on emulator.Pluri
J
1

I've been trying to solve this for hours and no solutions worked, since I use the new Splash API, I fixed it by replacing enableEdgeToEdge() before installSplashScreen() and it worked. Solved!!

Jana answered 27/7, 2024 at 8:58 Comment(0)
P
0

If application does not apply postSplashScreenTheme theme by default, changing theme programmatically can be solution for this problem!

It could be changed in MainActivity!

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setTheme(R.style.Theme_Driver) // actionBar?.hide()

        setContent {
            DriverTheme {
                AppUi(this, true)
            }
        }
    }
}

After that, there is no need to use actionBar?.hide().

Plutonic answered 1/5, 2024 at 3:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.