Williams Williams - 1 year ago 473
Android Question

Set OnClick Listener on Action Bar Title in Android

I am working on android application where I am using

so there one is navigation drawer icon to open it and title of
. I want to set a click listener on title of
such that it start a new
and set click listener different on navigation drawer icon to open navigation drawer menu.

I achieved a click on navigation drawer icon but when I click on title of
title also then it open the navigation drawer menu. Is there any way to set different click listener on title of

Thanks in advance.

Answer Source

Try adding this code under the onCreate() function. This will grab the resource the action bar title is under, and assign it an id you can use to add an OnClickListener to. Let me know how it goes!

final int abTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
findViewById(abTitleId).setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
    //Do something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download