This is my code. I am following a tutorial on Youtube. When I use android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
the screen does not show the splash screen and shows a blank screen instead. My code is as the following.
<activity
android:name="com.nowate.customerapp.activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This is the proper way to add a splash screen to your app. It doesn't take any fixed time to display it because it is showing while the app really loads.
styles.xml
: <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
AndroidManifest
to your launcher activity (don't create a new activity just for a splash screen):<activity
android:name="com.nowate.customerapp.activity.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
onCreate()
method set the original theme befor setting the layout:setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid android:color="@color/black" />
</shape>
</item>
<item
android:gravity="center"
android:drawable="@drawable/ic_loading"/>
</layer-list>