繁体   English   中英

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

[英]Splash screen still exist in next activity android

由于此教程,我创建了一个初始屏幕: 正确的初始屏幕

但是我有一个问题,当我创建新活动时,初始屏幕始终显示 在此处输入图片说明

它仅涵盖整个活动布局,是否有必要将其删除? 我是Android新手。 我不知道如何在Google上搜索此问题。 请帮忙。

IMO, 是初始屏幕的最佳教程

创建一个可绘制的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>

添加主题

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

添加到您的清单

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

添加启动活动到您的主要活动

public class SplashActivity extends AppCompatActivity {

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

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

}

我认为您应该将主应用程序替换为启动主题。 因此,请分开您的主要应用程序主题和初始主题。

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

//飞溅主题

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

更改XML主题

暂无
暂无

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

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