Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set OnClick Listener on Action Bar Title in Android

I am working on android application where I am using ActionBar so there one is navigation drawer icon to open it and title of ActionBar in ActionBar. I want to set a click listener on title of ActionBar such that it start a new Activity 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 ActionBar title also then it open the navigation drawer menu. Is there any way to set different click listener on title of ActionBar.

Thanks in advance.

like image 659
N Sharma Avatar asked Jul 19 '14 08:07

N Sharma


1 Answers

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() {  @Override public void onClick(View v) {     //Do something     } }); 
like image 135
Jake Weso Avatar answered Sep 28 '22 00:09

Jake Weso