123

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.

buczek
  • 2,011
  • 7
  • 29
  • 40
Anonymous
  • 1,389
  • 3
  • 11
  • 16

18 Answers18

170

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>

ireq
  • 1,741
  • 1
  • 10
  • 2
  • Although this works like a charm, there is a bit of a lag in loading the app when a user clicks on the icon to launch the app. Other than this, no particular tradeoff. – Han Apr 04 '19 at 06:42
  • 3
    I think this makes a delay in app starting – MrinmoyMk Oct 11 '20 at 09:24
  • 2
    This is not a good solution, actually is not a solution at all, just makes the white screen Transparent but still takes some seconds to load the Launcher screen, feels like a buggy app – dicarlomagnus Jan 12 '22 at 21:01
111

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----
}
Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
user543
  • 3,623
  • 2
  • 16
  • 14
  • 4
    but using `final ActionBar actionBar = getActionBar();` will return null when the Theme is translucent – Someone Somewhere Apr 26 '14 at 07:51
  • 20
    Pankaj - yes, I learned that the bad UI experience was due to the "preview" window... apparently someone at Google decided that a white preview window was really awesome to use by default. However, in an app that uses a dark background it's a really bad idea. The solution is to create a custom style for your app and specify 'android:windowBackground' to the color you want to use. See the section "the perfect preview window" http://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous/ – Someone Somewhere Jun 20 '14 at 15:26
  • Thanks buddy i was in a hunt for Theme.Translucent.NoTitleBar :) – manukv Feb 03 '16 at 10:53
  • 2
    @Hagai L It's give me an error like as "java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity." – TejaDroid May 27 '16 at 09:46
  • 1
    android:theme="@android:style/Theme.Translucent.NoTitleBar" did not work for me, any suggestions? – jay Aug 01 '16 at 08:01
  • I set the android:theme on application tag. Is that different from setting it on Activity tag in the manifest? – Kala J Aug 11 '16 at 11:37
  • 1
    @TejaDroid to get stop error "java.lang.IllegalStateException" you have to extends your Activity by android.app.Activity, right now you are using AppCompactActivity. So for AppCompactActivity you cannot use normal themes. – Ready Android Jan 11 '18 at 05:14
  • 1
    When I try with Theme.Translucent.NoTitleBar then app is taking time in lauching. It seems like first launch activity is drawing the translucent theme to overcome the white screen issue and then its draw the content view. Any idea about this? How to overcome this delay issue, I checked with Play Store app also that is also taking time to launch but very less approx 300ms but mine is taking 700ms to 1s. – Ready Android Jan 11 '18 at 05:17
73

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">
Tarun Deep Attri
  • 8,174
  • 8
  • 41
  • 56
8

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.

Blo
  • 11,903
  • 5
  • 45
  • 99
6

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.

luiscosta
  • 855
  • 1
  • 10
  • 16
4

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>
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
4

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.

Rajesh.k
  • 2,327
  • 1
  • 16
  • 19
3

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!

Community
  • 1
  • 1
Igor Fridman
  • 1,267
  • 1
  • 16
  • 30
  • 1
    i tried this solution many times as everywhere wrote this same solution, it couldn't work -- > but your BUT save my time my Activity extends AppCompatActivity that's why it's not working i changed it to activity now it works thank you man!! – Rucha Bhatt Joshi Mar 03 '17 at 05:47
2

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>
Rocky
  • 537
  • 4
  • 5
2

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.

divaPrajapati09
  • 170
  • 1
  • 12
  • Please add the details directly to your answer. Links can become invalid, that's why we like for the answer to contain the actual content, the link being only supplementary. – O.O.Balance Jun 24 '18 at 08:52
  • The link is to her own blog post, and it's the same info. >.> Also, as others have said elsewhere here making it translucent leaves it inaccessible later. – LabGecko Aug 09 '23 at 11:22
1

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!

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
phoenix
  • 496
  • 3
  • 11
1

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.

Mina Farid
  • 5,041
  • 4
  • 39
  • 46
1

Its Solution is very Simple!

There are Three Basic Reasons for This problem

  1. You are doing Heavy / Long running / Complex task in onCreateVeiw Function.
  2. If your are using Thread. Then Thread Sleep time may be very large.
  3. If You are using any Third Party library. Which is initialize at app start up time it may leads 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.

Sheharyar Ejaz
  • 2,808
  • 1
  • 14
  • 15
1

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>
Farid Haq
  • 3,728
  • 1
  • 21
  • 15
1

This solved the problem :

Edit your styles.xml file :


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.

Julien J
  • 2,826
  • 2
  • 25
  • 28
1

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>
Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
0

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.

Hitesh sapra
  • 248
  • 2
  • 12
  • Code-only answers are discouraged. Please click on [edit] and add some words summarising how your code addresses the question, or perhaps explain how your answer differs from the previous answer/answers. [From Review](https://stackoverflow.com/review/late-answers/22067254) – Nick Jan 30 '19 at 06:03
0

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

Atul Tiwaree
  • 27
  • 1
  • 5