启动画面背景在MainActivity中可见

时间:2019-06-12 08:43:57

标签: android

我正在尝试实现启动屏幕,我目前正在按照正确的方式实施此guide(带有代码的GitHub repo)。但是我遇到了问题,因为我的MainActivity继承了初始屏幕中使用的可绘制背景。

这是SplashActivity.java的代码:

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

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

以下是AndroidMainfest.xml的详细信息:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:theme="@style/splashScreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"></activity>

        <service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </application>

这里是styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">#205CA7</item>
        <item name="colorPrimaryDark">#164074</item>
        <item name="colorAccent">#4c7cb8</item>
    </style>

    <style name="splashScreenTheme" parent="AppTheme">
        <item name="android:windowBackground">@drawable/splash</item>
        <!--<item name="android:windowTranslucentStatus">true</item>-->
        <!--<item name="android:windowTranslucentNavigation">true</item>-->
    </style>
</resources>

0 个答案:

没有答案