最佳答案
我使用 安卓喷气背包中的 导航来在屏幕之间导航。 现在我想动态设置 startDestination。
我有一个名为 MainActivity 的活动 还有两个片段,片段 A 和片段 B。
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?