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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With