Nav Controller工具栏父子导航

问题描述 投票:0回答:1

我正在将Jetpack导航控制器与Side Drawer一起使用。

我的MainFragment.kt看起来像这样:

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/root"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center">


        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:elevation="4dp"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <fragment
                android:id="@+id/nav_host_home_fragment"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:defaultNavHost="true"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/toolbar"
                app:navGraph="@navigation/nav_home" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    <com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
            android:id="@+id/slider"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true" />

</androidx.drawerlayout.widget.DrawerLayout>

我的片段A有一个recyclerView,它具有一个onclick列表器以打开另一个片段:Adapter.kt

holder.itemView.setOnClickListener { v ->
  Log.d("Clicked", object.name)
  v.findNavController().navigate(R.id.action_FragmentA_to_FragmentB,null,navOptions)
}

但是我需要一种将工具栏从汉堡包图标更改为十字形的方法。

我一直在尝试不同的方法,但是找不到找到这种方法的方法。

android navigation-drawer toolbar android-toolbar android-jetpack
1个回答
0
投票
您将在setupWithNavController()中使用setupWithNavController()功能

Fragment

这将为您设置抽屉和工具栏侦听器。
© www.soinside.com 2019 - 2024. All rights reserved.