简体   繁体   English

启动画面仍存在于下一个活动android中

[英]Splash screen still exist in next activity android

I created a splash screen due to this tutorial: Splash Screen right way 由于此教程,我创建了一个初始屏幕: 正确的初始屏幕

But I have a problem that the splash screen always on display when I create new activity 但是我有一个问题,当我创建新活动时,初始屏幕始终显示 在此处输入图片说明

It just cover the whole activity layout, is there anyway to remove it? 它仅涵盖整个活动布局,是否有必要将其删除? I'm new to Android. 我是Android新手。 I dont know how to search this problem on Google. 我不知道如何在Google上搜索此问题。 Please help. 请帮忙。

IMO, this is the best tutorial for splash screens IMO, 是初始屏幕的最佳教程

create a drawable background_splash 创建一个可绘制的background_splash

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:drawable="@color/gray"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher"/>
</item>

add theme 添加主题

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

add to you manifiest 添加到您的清单

<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>

add splash activity that forwards to your main activity 添加启动活动到您的主要活动

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
}

} }

I think you should replace your main application with splash theme. 我认为您应该将主应用程序替换为启动主题。 So Please separate your main application theme and your splash theme. 因此,请分开您的主要应用程序主题和初始主题。

 <!-- 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>
</style>

// Splash Theme //飞溅主题

     <style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/splash</item>
  </style>

Change Theme in XML 更改XML主题

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

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