简体   繁体   中英

Splash screen showing on the background of main activity

I've set a splash screen on my app using this guide .

The background of my app is a transition color (changing color every few seconds using animation-list.

After the splash screen is shown (at the startup of the app), it stays in the background of the main activity.

screenshot

This is spalsh_screen.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@android:color/white"/>
    <item>
        <bitmap
            android:src="@drawable/talki_logo_big"
            android:gravity="center"/>
    </item>
</layer-list>

This is the animation_list.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:visible="true">
    <item
        android:drawable="@drawable/gradient_background_1"
        android:duration="2500" />
    <item
        android:drawable="@drawable/gradient_background_2"
        android:duration="2500" />
    <item
        android:drawable="@drawable/gradient_background_3"
        android:duration="2500" />
    <item
        android:drawable="@drawable/gradient_background_4"
        android:duration="2500" />
    <item
        android:drawable="@drawable/gradient_background_5"
        android:duration="2500" />
</animation-list>

Is there a way to make the splash screen disappear?

Thanks! :)

Try to add the property android:noHistory="true" in the manifest for your splashscreen activity.

A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it and maybe it won't show in the background.

The solution is already there in the tutorial you linked.

The easiest way to transition back to your normal theme is to call setTheme(R.style.AppTheme) before super.onCreate() and setContentView() .

public class MyMainActivity extends AppCompatActivity {
 @Override
  protected void onCreate(Bundle savedInstanceState) {
    // Make sure this is before calling super.onCreate
    setTheme(R.style.Theme_MyApp);
    super.onCreate(savedInstanceState);
    // ...
  }
}

Reason of Fail

You have set AppTheme.Launcher in manifest, which gives a background to Activity. Now after Activity is started, you need to change that theme to your App theme to remove the Splash Background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM