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

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...