简体   繁体   English

启动画面显示在主要活动的背景上

[英]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 这是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 这是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. 尝试在清单中为启动画面活动添加属性android:noHistory="true"

A value of "true" means that the activity will not leave a historical trace. 值为“ true”表示该活动将不会留下历史痕迹。 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() . 转换回常规主题的最简单方法是在super.onCreate()setContentView()之前调用setTheme(R.style.AppTheme) 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. 您已在清单中设置了AppTheme.Launcher ,它为Activity提供了背景。 Now after Activity is started, you need to change that theme to your App theme to remove the Splash Background. 现在,开始活动后,您需要将该主题更改为您的应用程序主题,以删除启动画面背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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