我正在尝试将工具栏绑定到导航控制器,为此我使用以下代码:
NavigationUI.setupWithNavController(toolbar, NavHostFragment.findNavController(nav_host))
Run Code Online (Sandbox Code Playgroud)
在菜单文件中,我提供了应用程序应导航到的片段的 ID,如下所示:
<item
android:id="@+id/menuFragment"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
Run Code Online (Sandbox Code Playgroud)
我有一个简单的导航图文件,如下所示:
<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/nav_graph"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.vapoyan.myapplication.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_homeFragment_to_menuFragment"
app:destination="@id/menuFragment" />
</fragment>
<fragment
android:id="@+id/menuFragment"
android:name="com.vapoyan.myapplication.MenuFragment"
android:label="fragment_menu"
tools:layout="@layout/fragment_menu" />
</navigation>
Run Code Online (Sandbox Code Playgroud)
有没有人有经验或可以建议我如何解决问题,导航组件是否支持工具栏?
任何示例代码或参考?