微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 导航架构组件 – 启动画面

我想知道如何使用Navigation Architecture Component实现启动画面.

直到现在我有这样的事情

enter image description here

用户必须首次在ProfileFragment中设置其个人资料,并可以从ChatFragment编辑他们的个人资料.

我的问题是我不知道如何在导航后从堆栈中删除SplashFragment.我见过conditional navigation但不太明白.

解决方法:

要实现正确的Splash屏幕,请按照@Sander指出的this教程进行操作.
简而言之,要实现Splash屏幕,你需要这样的SplashTheme:

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

splash_background drawable应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:opacity="opaque"> <!-- android:opacity="opaque" should be here -->
    <item>
        <!--this is your background, you can use color, gradient etc.-->
        <color android:color="@color/colorPrimary"/>
        <!--<shape>
              <gradient
                   android:angle="315"
                   android:endColor="#1a82ff"
                   android:startColor="#2100d3"
                   android:type="linear"/>
        </shape> -->
    </item>
    <item>
        <bitmap android:src="@drawable/ic_logo"
                android:gravity="center"/>
    </item>
</layer-list>

在Manifest中,只需将SplashTheme添加到您的Activity中:

<activity android:name=".ui.MainActivity"
              android:theme="@style/SplashTheme">

然后在MainActivity中返回你的常规AppTheme在onCreate之前执行此操作,然后再调用

override fun onCreate(savedInstanceState: Bundle?) {
    setTheme(R.style.AppTheme)
    super.onCreate(savedInstanceState)
    .....

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐