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

查看:62
本文介绍了导航体系结构组件-带登录屏幕的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.

我想的一种方法是将NaHostFragment的设置延迟到我的Activity中,直到完成所有设置为止. 因此,基本上可以切换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天全站免登陆