How To Override ActionBar Items In GreenDroid ActionBar

When you inherit from any Activity class of the GreenDroid library, you can override the action bar items of the action bar by overriding the method onHandleActionBarItemClick().

Check the sample code below.

The code above uses the parameter position to indicate the index position of the action bar item that you added on the right side of the action bar. If you want to specifically point to the action bar’s id, use the item parameter instead using item.getItemId() as the parameter in the switch area.

The “default” points to the home button (located on the left most).

Related Posts Plugin for WordPress, Blogger...

6 comments

  1. Are you sure for the home button, it even doesn’t jump to the onHandleActionBarItemClick() method when selecting home button for my case. It works properly with the other items.

  2. @doreamon: if you want to change the activity class of the home button, then you would have to override and change

    public Class getHomeActivityClass() {
    return ?????
    }

    in your GDApplication class.

  3. So the sentence in your post : “The “default” points to the home button” is not so correct, right? 🙂

  4. it does. change the Activity class in the getHomeActivityClass() method. click on the home button of the action bar and it will go to the Activity class that is specified. 🙂

  5. I have turned the home button into a back button with this code which is in an OnActionBarListener (HOME_ITEM is -1 in the GreenDroid source)

    public void onActionBarItemClicked(int position) {
    if (position==HOME_ITEM) this.finish();
    else getActionBar().setTitle(“somethinge else clicked”);

    }// end method

Leave a Reply

Your email address will not be published. Required fields are marked *