cxphong
cxphong

Reputation: 857

White background when Android app start up

Every when my app starts up, there's a white background displays in a short time. Despite of using splash screen, the problem is still exists. I would like to set the start up screen to black instead of white as default!

This is my splash's screen activity:

public class SplashActivity extends Activity {

private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 1;    // Sleep for some time

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
    setContentView(R.layout.splash);

    // Start timer and launch main activity
    IntentLauncher launcher = new IntentLauncher();
    launcher.start();
}

private class IntentLauncher extends Thread {

    /**
      * Sleep for some time and than start new activity.
      */ 
    @Override
    public void run() {
        try {
            // Sleeping
            Thread.sleep(SLEEP_TIME*1000);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }

        // Start main activity
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        SplashActivity.this.startActivity(intent);
        SplashActivity.this.finish();
    }

}

@Override
protected void onPause() {
    super.onPause();
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
}

Upvotes: 16

Views: 21799

Answers (7)

Arun Gohil
Arun Gohil

Reputation: 61

In styles.xml, theme applied for SplashActivity, add the following line

<item name="android:windowBackground">@drawable/background</item>

where @drawable/background is the background you applied for your Splash Screen or it could be any color you need.

Upvotes: 2

derfect
derfect

Reputation: 642

in drawable folder, create your own starting_screen.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <!-- black background -->
            <solid android:color="@color/colorBlack" />
        </shape>
    </item>
    <!-- launcher icon -->
    <item android:drawable="@mipmap/ic_launcher_foreground" android:height="150dp" android:width="150dp" android:gravity="center" />
</layer-list>

then add this to your style

<item name="android:windowBackground">@drawable/starting_screen</item>

now a black screen with your launcher icon will appear whenever you launch your application

Upvotes: 7

djunod
djunod

Reputation: 4976

in styles.xml, in the theme specified in your AndroidManifest.xml, add the following line:

<item name="android:windowBackground">@android:color/black</item>

Upvotes: 31

Ranjit
Ranjit

Reputation: 61

If you want to change the white screen that appears before splash screen to black just change the theme for the SplashActivity rather than for the entire app.

You can use this:

<activity
    android:name="your.package.SplashActivity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
       <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
</activity>

Hope this helps.

Upvotes: 5

Rahul Gupta
Rahul Gupta

Reputation: 5295

you have set splash.xml when your activity starts. change that, change the parent background to black or whichever color you wan. it will work, or change the splash.xml theme to holo_dark or any other theme

Upvotes: 0

jspurlock
jspurlock

Reputation: 1476

You can change the starting window background color using a custom theme. See Styles and Themes for an example.

Upvotes: 2

SweetWisher ツ
SweetWisher ツ

Reputation: 7306

Use this tag in your manifest:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

instead of :

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Upvotes: 11

Related Questions