Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge Android actionbar with menu tabs

We are trying to create an application for Android. And we are wondering if it's possible to merge the menu with the actionbar in potrait mode, like the way it is in Landscape mode in 4.0 and on Honeycomb tablets (see screenshots below).

Is this possible? If yes, how?

like image 979
Arjan de Wit Avatar asked Jul 03 '12 10:07

Arjan de Wit


1 Answers

If you want to add more icons to actionbar, you can add.

For example : (This master.xml must be in menu folder)

<menu xmlns:YourApp="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/actionBarFilterItem"
      android:icon="@drawable/crystal_icon_filter"
      android:title="@string/changeFilter"
     YourAPPNAME:showAsAction="always"
   />

        <item android:id="@+id/actionBarSettingsItem"
      android:icon="@drawable/crystal_icon_settings"
      android:title="@string/action_settings"
     YourAPPNAME:showAsAction="always"
   />

In the activity you must set the inflater like :

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.master, menu);

    return super.onCreateOptionsMenu(menu);
}

And to set onClick events you can use :

    @Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // Handle action buttons
    switch(item.getItemId()) {
    case R.id.actionBarFilterItem:
        //TODO Your action
        return true;
    case R.id.actionBarSettingsItem:
        //TODO Your action
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

Good luck

like image 63
Warwicky Avatar answered Oct 05 '22 19:10

Warwicky