Home » Android » android – Actionbar Sherlock: Setting and hiding title bar

android – Actionbar Sherlock: Setting and hiding title bar

Posted by: admin May 14, 2020 Leave a comment


I’m new to ActionBarSherlock, and am having two problems:

First, I just want to be able to set the title of the action bar, but it doesn’t work when I call it like this:

final ActionBar actionBar = (ActionBar) findViewById(R.id.actionBar);
actionBar.setTitle("test title");

Where the corresponding xml object looks like this:

    android:layout_alignParentTop="true" />

(This is modeled after the github example: https://github.com/johannilsson/android-actionbar/blob/master/actionbarexample/src/com/markupartist/android/actionbar/example/HomeActivity.java). In other places on the web, I see reference to getSupportActionBar(), but I’m not clear how or where to call this.

Second, in another place I just want to be able to hide the Activity’s title bar altogether. I’m trying to do this by calling:


but I can’t even get this to compile. The error I’m getting is:

"The method setDisplayShowTitleEnabled(boolean) is undefined for the type

In both cases, I guess the Actionbar Sherlock overrides are involved in the problem. Any suggestions how to make this work?

Thanks very much.

How to&Answers:

You seem to be mixing up two different ActionBar implementations. ActionBarSherlock is an extension of the compatibility library provided by Google. The methods used with ActionBarSherlock are almost identical to the native ActionBar found in Android 3.0+ http://actionbarsherlock.com/

The Github link provided (and code you are using) is a custom implementation of an actionbar https://github.com/johannilsson/android-actionbar.

I would advise you use ActionBar sherlock and follow the usage guide here http://actionbarsherlock.com/usage.html

There is also an ActionBarSherlock getting started video here http://www.youtube.com/watch?feature=player_embedded&v=4GJ6yY1lNNY


Setting the ActionBar title


Hiding and showing the ActionBar



You need to import com.actionbarsherlock.view.Window so that it secretly uses the long version of this method.