Reputation: 1389
I have an android app which displays a white screen for 2 seconds on startup. My other apps don't do this, but this one does. I have also implemented a splashscreen with the hope that it would fix this. Should I increase my splash screen sleep time? Thanks.
Upvotes: 123
Views: 128979
Reputation: 105
Setting "android:windowBackground" with the image, removes the white/black screen and shows the image instead
<item name="android:windowBackground">@drawable/launch_screen</item>
where "launch_screen" is an image of format png placed inside drawable folder
Note: You do not need to specify the format while using image
Upvotes: 0
Reputation: 515
I encountered a similar problem and to overcome it, I implemented the below code in styles, i.e res->values->styles->resource tag
<item name="android:windowDisablePreview">true</item>
Here is the whole code:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
</style>
Upvotes: 1
Reputation: 3526
This solved the problem :
Paste the code below :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
And don't forget to make the modifications in the AndroidManifest.xml file. (theme's name)
Be careful about the declaration order of the activities in this file.
Upvotes: 0
Reputation: 4229
White background is caused because of the Android starts while the app loads on memory, and it can be avoided if you just add this 2 line of code under SplashTheme.
<item name="android:windowDisablePreview">true</item>
<item name="android:windowIsTranslucent">true</item>
Upvotes: 1
Reputation: 2858
Its Solution is very Simple!
There are Three Basic Reasons for This problem
Solutions:
Solution 1:
Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
Solution 2:
Reduce the Thread Sleep time.
Solution 3:
Remove the Third party library at app initialize at implement them with some good strategy.
In my Case i am using Sugar ORM which leads this problem.
Share to improve.
Upvotes: 1
Reputation: 256
Try the following code:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
This code works for me and will work on all Android devices.
Upvotes: 0
Reputation: 3633
Just mention the transparent theme to the starting activity in the AndroidManifest.xml file.
Like:
<activity
android:name="first Activity Name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and extend that screen with Activity
class in place of AppCompatActivity
.
like :
public class SplashScreenActivity extends Activity{
----YOUR CODE GOES HERE----
}
Upvotes: 112
Reputation: 170
i also had the same problem in one of my project. I resolved it by adding some following parameters in the theme provided to the splash screen.
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
You can find the reason and resolution in this blog post written by me. Hope it helps.
Upvotes: 2
Reputation: 547
Below is the link that suggests how to design Splash screen. To avoid white/black background we need to define a theme with splash background and set that theme to splash in manifest file.
https://android.jlelse.eu/right-way-to-create-splash-screen-on-android-e7f1709ba154
splash_background.xml inside res/drawable folder
<?xml version=”1.0" encoding=”utf-8"?>
<layer-list xmlns:android=”http://schemas.android.com/apk/res/android">
<item android:drawable=”@color/colorPrimary” />
<item>
<bitmap
android:gravity=”center”
android:src=”@mipmap/ic_launcher” />
</item>
</layer-list>
Add below styles
<!-- Base application theme. -->
<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>
<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
In Manifest set theme as shown below
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 2
Reputation: 5897
you should disable Instant Run android studio Settings.
File>Settings>Build,Execution, Deployment>Instant Run unCheck all options shown there.
Note: White screen Issue due to Instant Run is only for Debug builds,this Issue will not appear on release builds.
Upvotes: 1
Reputation: 2447
The white background is coming from the Apptheme.You can show something useful like your application logo instead of white screen.it can be done using custom theme.in your app Theme just add
android:windowBackground=""
attribute. The attribute value may be a image or layered list or any color.
Upvotes: 4
Reputation: 1307
The user543 answer is perfect
<activity
android:name="first Activity Name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But:
You'r LAUNCHER Activity must extands Activity, not AppCompatActivity as it came by default!
Upvotes: 3
Reputation: 8149
Both properties works use any one of them.
<style name="AppBaseThemeDark" parent="@style/Theme.AppCompat">
<!--your other properties -->
<!--<item name="android:windowDisablePreview">true</item>-->
<item name="android:windowBackground">@null</item>
<!--your other properties -->
</style>
Upvotes: 4
Reputation: 855
This is my AppTheme on an example app:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
As you can see, I have the default colors and then I added the android:windowIsTranslucent
and set it to true
.
As far as I know as an Android Developer, this is the only thing you need to set in order to hide the white screen on the start of the application.
Upvotes: 6
Reputation: 496
It can be fixed by setting the theme in your manifest as
<activity
android:name=".MySplashActivityName"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and after that if you are getting
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
then you may need to extend Activity instead of AppCompatActivity in your MySplashActivity.
Hope it helps!
Upvotes: 1
Reputation: 8674
Make a style in you style.xml as follows :
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
and use it with your activity in AndroidManifest as:
<activity android:name=".ActivitySplash" android:theme="@style/Theme.Transparent">
Upvotes: 73
Reputation: 1731
Put this in a custom style and it solves all the problems. Using the hacky translucent fix will make your task bar and nav bar translucent and make the splashscreen or main screen look like spaghetti.
<item name="android:windowDisablePreview">true</item>
Upvotes: 169
Reputation: 11988
You should read this great post by Cyril Mottier: Android App launching made gorgeous
You need to customise your Theme
in style.xml and avoid to customise in your onCreate
as ActionBar.setIcon/setTitle/etc.
See also the Documentation on Performance Tips by Google.
Use Trace View
and Hierarchy Viewer
to see the time to display your Views: Android Performance Optimization / Performance Tuning On Android
Use AsyncTask
to display some views.
Upvotes: 8