【发布时间】:2019-01-26 11:56:27
【问题描述】:
我正在使用Android Jetpack 中的Navigation 在屏幕之间导航。 现在我想动态设置 startDestination。
我有一个名为 MainActivity 的活动 还有两个 Fragment,FragmentA 和 FragmentB。
var isAllSetUp : Boolean = // It is dynamic and I’m getting this from Preferences.
If(isAllSetUp)
{
// show FragmentA
}
else
{
//show FragmentB
}
我想使用导航架构组件设置上述流程。目前我已经使用了 startDestionation 如下,但它没有满足我的要求。
<navigation 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:id="@+id/lrf_navigation"
app:startDestination="@id/fragmentA">
<fragment
android:id="@+id/fragmentA"
android:name="com.mindinventory.FragmentA"
android:label="fragment_a"
tools:layout="@layout/fragment_a" />
</navigation>
是否可以使用 Android 导航架构组件有条件地设置 startDestination?
【问题讨论】:
-
#navigation-architecture-component #navigation-graph
-
嗨@NileshRathod,如果我先打开FragmentA 然后打开FragmentB,这是可行的。但我想以编程方式设置 StartDestination。你有同样的解决方案吗?
-
试试这个
NavigationUI.onNavDestinationSelected(menuItem, navController.getNavController()); -
我想在没有菜单或任何其他导航控件的情况下执行上述操作。也许没有办法有条件地设置 startDestination。所以现在我按照你的建议使用了 [stackoverflow.com/questions/51173002/…。
标签: android android-jetpack android-architecture-navigation