Merge Android action bar with menu tabs

We are trying to create an Android app. And we are wondering if it is possible to combine the menu with the action bar in potrait mode, similar to how it happens in landscape mode in 4.0 and on Honeycomb tablets (see. Screenshots below).

Is it possible? If so, how?

+7
source share
1 answer

If you want to add other icons to the action bar, you can add.

For example: (This master.xml file should be in the 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 this exercise, you should establish an inflate as:

  @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.

+1
source

All Articles