dus*_*awn 3 android android-fragments android-architecture-navigation
我的 MainActivity 设置如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
底部导航有 3 个选项卡,只有在执行一些初始身份验证和设置用户调用后才能显示。
在让用户开始使用底部导航视图之前,显示加载/设置用户屏幕的最佳方式是什么?
我想到的一种方法是延迟 Activity 中 NaHostFragment 的设置,直到所有设置完成。所以基本上切换mainNavigationFragment和的可见性BottomNavigationView,直到设置完成。
还有其他想法吗?
NavigationUI文档实际上使用隐藏 aBottomNavigationView作为示例。您还可以使用OnDestinationChangedListener来更新您的可见性BottomNavigationView,例如,仅在用户位于登录屏幕上时隐藏它(请注意,根据条件导航文档,您不应该在图表的起始目的地中执行此操作,但将用户重定向到这些屏幕):
navController.addOnDestinationChangedListener { _, destination, _ ->
if(destination.parent?.id == R.id.login) {
bottomNavigationView.visibility = View.GONE
} else {
bottomNavigationView.visibility = View.VISIBLE
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
2045 次 |
| 最近记录: |