您好,我正在更改导航文件中片段的标签,但是工具栏中的片段标题没有更改,有什么解决方法吗?
<fragment
android:id="@+id/navHostFragment"
android:name="com.example.androidtask.view.UsersList"
android:label="@string/user_list"
tools:layout="@layout/fragment_users_list">
<action
android:id="@+id/submit_user"
app:destination="@id/addUser" />
</fragment>
答案 0 :(得分:2)
您需要将ActionBar设置为可用于导航,并将此代码添加到活动onCreate()
val navController = findNavController(R.id.nav_host_fragment)// where nav_host_fragment is the id for your Main NavHost fragment
val appBarConfiguration = AppBarConfiguration(navController.graph)
setupActionBarWithNavController(navController, appBarConfiguration)
有关更多信息,请检查this