blank screen comes before splash
Generally speaking, splash screens are not recommended for an app but if you really must.
Android will load a blank layout before it loads an activity layout based on the theme you have set for it. The solution is to set the theme of the splash activity to a transparent one.
Create a transparent theme in res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
Then set the theme in your manifest
<activity android:name=".SplashActivity" android:theme="@style/Theme.Transparent">
...
</activity>
Black screen before Splash screen appear in android
Add a theme with the background you are using to your application tag in the manifest file to prevent the black screen to be drawn.
theme.xml
<resources>
<!-- Base application theme is the default theme. -->
<style name="Theme" parent="android:style/Theme" />
<style name="Theme.MyAppTheme" parent="Theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/my_app_background</item>
</style>
</resources>
AndroidManifest.xml
....
<application
android:name="@string/app_name"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.MyAppTheme"
>
....
Read why there is a black screen here
Black screen after splash
I found a solution after a while:
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Timer().schedule(1000) {
if (sharedPrefs.isUserLogged) {
startActivity(intentFor<MainActivity>().clearTask().newTask())
}else{
startActivity(intentFor<LoginActivity>().clearTask().newTask())
}
}
}
}
and I set the theme like this:
<style name="AppTheme.Launch">
<item name="android:windowBackground">@drawable/my_splash</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
How can I remove white screen which appear before splash screen?
Finally got my answer Splash Screen in Right Way. I do just following.
In values->styles.xml I created splash screen background image
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
For below api 19, in values-19->styles.xml I used
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
I removed setContentview()
from SplashActivity and added style for splash screen in Manifest.xml
file android:theme="@style/AppTheme.Splash"
Related Topics
How to Integrate Opencv 4.0 into a Pure C++ Android Ndk Project
Android 4.0.1 Breaks Webview HTML 5 Local Storage
Disabling Android's Chrome Pull-Down-To-Refresh Feature
Android: HTML in Textview with Link Clickable
What Is The Easiest Way to Use Svg Images in Android
Activity.Finish() Called But Activity Stays Loaded in Memory
In HTML5, How to Keep an Android Device's Screen On
Android Back Button on a Progressive Web Application Closes De App
Does 'Meta Name="Google-Play-App"' Work
Placeholder Text for an Input Type="Number" Does Not Show in Webkit Ics
CSS Reference to Phone's Emoji Font
Using Numberpicker Widget with Strings
Resources and Layout Direction Rendered Incorrectly Only on Android 8.0 and Above
Firestorepagingadapter Not Receiving Realtime Updates
Getting Error "Gradle Dsl Method Not Found: 'Compile()'" When Syncing Build.Gradle