Кнопка «Назад» не нажимается. Пробовал этот ответ , но он не работает.
override fun onCreate(savedInstanceState: Bundle?) {
val toolbar = findViewById<Toolbar>(R.id.toolbar)
toolbar.setNavigationIcon(R.drawable.ic_navbar_cancel)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowHomeEnabled(true)
toolbar.setNavigationOnClickListener { Log.d("Test", "Clicked!") }
}
title_toolbar. xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app_bar_layout"
style="?attr/appBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@id/toolbar"
style="?attr/toolBarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<TextView
android:id="@+id/toolbar_title"
style="?attr/toolBarTitleStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:fontFamily="@font/intro_bold_caps"
android:paddingStart="0dp"
android:paddingEnd="6dp" />
</androidx.appcompat.widget.Toolbar>
<View
android:id="@+id/toolbar_shadow_pre_lollipop"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="@id/toolbar"
android:background="@drawable/toolbar_shadow_pre_lollipop" />
</com.google.android.material.appbar.AppBarLayout>
ic_navbar_cancel. xml
<path
android:fillColor="#003b5a"
android:pathData="M18,18 L30,30 M18,30 L30,18"
android:strokeColor="#003b5a"
android:strokeWidth="3"/>