tagged: android-actionbar

Android: Actionbar setup

Create an options menu as normal. I.e. in your onCreate() method issue:


And override methods to create the options menu

 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.yourmenu, menu);
    super.onCreateOptionsMenu(menu, inflater);

The yourmenu menu will live in res/menu/yourmenu.xml and look something like:

 <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_refresh"

The showAsAction attribute means you'll always see it - it won't be folded into a menu.
Et voila.

android android-actionbar

Android: ActionBar home up button

To create a little back or up icon near your icon on the action bar, call getActionBar().setDisplayHomeAsUpEnabled(true);
In the onMenuItemSelected method, listen for the android.R.id.home item. Then either finish() the activity to go back to previous one, or start a new activity if you want.

public boolean onMenuItemSelected(int featureId, MenuItem item) {

    switch (item.getItemId()) {

		case android.R.id.home:


			return true;	    




    return super.onMenuItemSelected(featureId, item);


android android-actionbar

Page 1 of 1