Toolbar click listener is not applying

setnavigationonclicklistener
contentinsetstartwithnavigation
android toolbar
android toolbar navigation icon
android toolbar height
different action bar for different fragments
toolbar button android
kendo grid toolbar create click event

I have following code in my Fragment to setup toolbar :

with(root) {
            with(activity as AppCompatActivity) {
                setupActionBar(toolbar) {
                    setDisplayHomeAsUpEnabled(true)
                    setDisplayShowHomeEnabled(true)
                }
            }
            toolbar.setNavigationOnClickListener { activity?.finish() }
        }

Here is my setupActionBar method :

fun AppCompatActivity.setupActionBar(toolbar : Toolbar, action: ActionBar.() -> Unit) {
    setSupportActionBar(toolbar)
    supportActionBar?.run {
        action()
    }
}

And toolbar in my layout :

    <?xml version="1.0" encoding="utf-8"?>
<layout 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"
        tools:context=".ui.detail.DetailFragment">

    <data>
        <variable
                name="artist"
                type="com.sample.android.lastfm.model.LastFmArtist"/>
    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    app:collapsedTitleTextAppearance="@style/CollapsedToolbar"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleTextAppearance="@style/ExpandedToolbar"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
                    app:title="@{artist.name}">

                <ImageView
                        android:id="@+id/movie_poster"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="centerCrop"
                        app:layout_collapseMode="parallax"
                        app:imageUrl="@{artist.images}"
                        tools:ignore="contentDescription"/>

                <androidx.appcompat.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:minHeight="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:theme="@style/Toolbar"/>

                <com.google.android.material.tabs.TabLayout
                        android:id="@+id/tabLayout"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/custom_tab_layout_height"
                        app:tabGravity="fill"
                        app:tabIndicatorColor="@color/colorAccent"
                        app:tabIndicatorHeight="4dp"
                        app:tabMode="fixed"/>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

        </com.google.android.material.appbar.AppBarLayout>

        <androidx.viewpager.widget.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>

When I click on toolbar, it does not navigate me back to previous screen. It seems that it is not clickable.

(activity as AppCompatActivity).setSupportActionBar(toolbar)
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)

then in your fragment

override onOptionsItemSelected

 override fun onOptionsItemSelected(item: MenuItem?): Boolean {

            when (item?.itemId) {

                android.R.id.home -> {
                 activity?.onBackPressed()
                    }

        }
     return true
}  

toolbar.setNavigationOnClickListener not working, The use of application icon plus title as a standard layout is discouraged on API click events if the items themselves do not have individual item click listeners. A ToolBar is a control which displays items vertically or horizontally. Buttons, ToggleButtons, and Separators are generally placed into ToolBar. You can also insert any Node into them. Overflow button will appear if there are too many items to fit in the ToolBar which allow selecting items that are not currently visible in the toolbar.

Add the toolbar to your fragment xml And try this code in your onCreateView

Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_back_button); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().onBackPressed(); } });

android.widget.Toolbar, function splitButtonClickHandler(e) { kendoConsole.log("SplitButton event: " + e. id + " is clicked."); } function onClick(e) { kendoConsole.log("ToolBar 'click' event� If a listener has never been created: Click plus (+) from the toolbar, or choose Edit > Create. The Choose Listener Name dialog box appears. Enter a unique listener name in the Listener Name field. Click OK. From the list in the right pane, select Listening Locations. Click Add Address. A new Address tab appears.

Toolbar should not be :

<androidx.appcompat.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:minHeight="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:theme="@style/Toolbar"/>

Rather it should be :

<androidx.appcompat.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:theme="@style/Toolbar"/>

Events demo of Kendo UI ToolBar Widget, Exercise: Add a toolbar to your application In case of the options menu, the user may not recognize that options are available in the application. OnClickListener() { @Override public void onClick(View v) { myListFragment. public static interface Toolbar.OnMenuItemClickListener androidx.appcompat.widget.Toolbar.OnMenuItemClickListener Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners.

Using the Android Toolbar (ActionBar) - Tutorial, There are two methods to add a back button on the toolbar. First, I'm gonna show you toolbar.setNavigationOnClickListener(new View.OnClickListener() { @ Override public void Do not forget to override it! If you have any� I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen – Click here to download the

Android Notes 24: How to add Back Button at Toolbar [UPDATED v2], The Toolbar plugin allows an application to create a native toolbar using JavaScript. Adds an event listener to the Toolbar. if the argument is not a function. Step 3: Add a click listener to the FAB. In this step, you add a click handler to the FAB that takes the user to a list of GDGs. You've added click handlers in previous codelabs, so the instructions are terse. In home_fragment.xml, in the <data> tag, define a variable viewModel for the provided HomeViewModel.

JSDoc: Namespace: Toolbar, This example demonstrates How to Set OnClick Listener on Action Bar Title in Android.Step 1 Toolbar android:id = "@+id/my_awesome_toolbar" android: layout_width = "match_parent" Let's try to run your application. I have a problem with a Save button on a toolbar firing the click event twice if the user double clicks the button as opposed to single clicking. Disabling the double click on the toolbar itself seems to make no difference as it is the actual save button that is being clicked twice.