Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionbar Sherlock: Setting and hiding title bar

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:

<com.myapp.prototype.ActionBar
    android:id="@+id/actionBar2"
    android:layout_width="fill_parent"
    android:layout_height="45dip" 
    android:layout_alignParentLeft="true"
    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:

    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);

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

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

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

Thanks very much.

like image 683
gcl1 Avatar asked May 29 '12 22:05

gcl1


2 Answers

Setting the ActionBar title

setTitle("Title")

Hiding and showing the ActionBar

getSupportActionBar().hide();
getSupportActionBar().show();
like image 189
Matthias Robbers Avatar answered Nov 05 '22 04:11

Matthias Robbers


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

like image 39
bencallis Avatar answered Nov 05 '22 04:11

bencallis