导航架构组件 - 带登录屏幕的 BottomNavigationView [英] Navigation Architecture Component - BottomNavigationView with Login Screen

查看:27
本文介绍了导航架构组件 - 带登录屏幕的 BottomNavigationView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MainActivity 设置如下所示:

I have my MainActivity setup which looks like this :

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.host.HostActivity">



    <fragment
        android:id="@+id/mainNavigationFragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_graph" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/main_nav_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>

底部导航有 3 个选项卡,只有在执行了一些初始身份验证和设置用户调用后才能显示.

And the bottom navigation has 3 tabs which can only be shown after some initial authentication and setup user calls have been performed.

在让用户开始使用底部导航视图之前显示加载/设置用户屏幕的最佳方式是什么.

What is the best way to show a Loading/Setting up user screen before I let user start using the bottom nav view.

我想的一种方法是在我的 Activity 中延迟 NaHostFragment 的设置,直到所有设置完成.所以基本上切换 mainNavigationFragmentBottomNavigationView 的可见性,直到设置完成.

One way I am thinking is to delay the setup of NaHostFragment in my Activity until all the setup is done. So basically toggle the visibility of mainNavigationFragment and BottomNavigationView till the setup is completed.

还有其他想法吗?

推荐答案

NavigationUI文档 实际上以隐藏 BottomNavigationView 为例.您还可以使用 OnDestinationChangedListener 更新您的 BottomNavigationView 的可见性,例如,仅在用户在登录屏幕上时隐藏它(请注意,根据 条件导航文档,您不应该在图表的起始目的地执行此操作,但是将用户重定向到这些屏幕):

The NavigationUI documentation actually uses hiding a BottomNavigationView as its example. You could also use an OnDestinationChangedListener to update the visibility of your BottomNavigationView, say, only hiding it while the user is on the login screen (note that as per the Conditional Navigation documentation, you shouldn't be doing this in the start destination of your graph, but redirecting users to those screens):

navController.addOnDestinationChangedListener { _, destination, _ ->
  if(destination.parent?.id == R.id.login) {
    bottomNavigationView.visibility = View.GONE
  } else {
    bottomNavigationView.visibility = View.VISIBLE
  }

}

这篇关于导航架构组件 - 带登录屏幕的 BottomNavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆