【发布时间】:2020-02-24 20:01:58
【问题描述】:
我正在使用 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 监听器来打开另一个片段: 适配器.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