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'.
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
}
}