How to include a common menu item in multiple menus in Android menu xml?

Inflating each menu and calling to super works great! Here is an example: @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.other, menu); return true; } You can control the order if super also adds more items by calling it before/after other inflates, or not call at all it to ignore those items.

How to add line divider for menu item Android

Make sure to call MenuCompat.setGroupDividerEnabled(menu, true); when you inflate your menu, otherwise groups will not be separated by divider! Example: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_activity_main, menu); MenuCompat.setGroupDividerEnabled(menu, true); return true; } And make sure to have different groups in your menu xml, e.g.: <menu> <group android:id=”@+id/sorting” > <item android:id=”@+id/action_sorting_new_old” android:title=”@string/action_sorting_new_old”/> <item android:id=”@+id/action_sorting_a_z” android:title=”@string/action_sorting_a_z”/> … Read more

What should I pass for root when inflating a layout to use for a MenuItem’s ActionView?

I would simply do it like this: menuItem.setActionView(R.layout.action_view_layout); Let Android inflate the view for you. If you need to do some extra changes on this ImageView call ImageView imageView = (ImageView) menuItem.getActionView(); Update In order to cater to your curiosity. That is what folks from Google do under the hood: public MenuItem setActionView(int resId) { … Read more

How to display menu item with icon and text in AppCompatActivity

@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.menu_patient_home_screen, menu); menu.add(0, 1, 1, menuIconWithText(getResources().getDrawable(R.mipmap.user_2), getResources().getString(R.string.action_profile))); menu.add(0, 2, 2, menuIconWithText(getResources().getDrawable(R.mipmap.add_user), getResources().getString(R.string.action_add_user))); menu.add(0, 3, 3, menuIconWithText(getResources().getDrawable(R.mipmap.switch_profile), getResources().getString(R.string.action_switch_profile))); menu.add(0, 4, 4, menuIconWithText(getResources().getDrawable(R.mipmap.logout), getResources().getString(R.string.action_sign_out))); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle … Read more

Mutually exclusive checkable menu items?

This may not be what you’re looking for, but you could write an extension for the MenuItem class that allows you to use something like the GroupName property of the RadioButton class. I slightly modified this handy example for similarly extending ToggleButton controls and reworked it a little for your situation and came up with … Read more

Android ActionBar MenuItem LowerCase

Solution for native ActionBar implementation: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <style name=”MyTheme” parent=”android:Theme.Holo”> <item name=”android:actionMenuTextAppearance”>@style/MyMenuTextAppearance</item> </style> <style name=”MyMenuTextAppearance” parent=”android:TextAppearance.Holo.Widget.ActionBar.Menu”> <item name=”android:textAllCaps”>false</item> </style> </resources> If you are using ActionBarSherlock there are two different approaches: 1) Create boolean resource abs__config_actionMenuItemAllCaps and set it to false: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <bool name=”abs__config_actionMenuItemAllCaps”>false</bool> </resources> 2) Or create theme with overriden … Read more