Menu overflow button on ActionBar/ActionBarSherlock - android

This app was designed before the deprecation of the hardware menu button, so now it automatically shows a menu overflow button at the bottom of our app. We'd rather it wedge itself to the right of our 4 tab bar items when needed.
If that's not doable, we'd at least like to be able to center the lonely menu overflow button like it appears on the first pic here -> http://www.droid-life.com/2012/05/30/dear-developers-can-we-quit-with-the-menu-button-already-and-adopt-an-action-overflow/
We are using ActionBarSherlock.

You must add it mannually with setAddOptionMenu(true);
and then create it in xml for example:
<item
android:id="#+id/video"
android:title="#string/video"
android:icon="#drawable/video"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/email"
android:title="#string/email"
android:icon="#drawable/email"
android:showAsAction="ifRoom|withText"
/>
Then inflate it
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.items, menu);
return super.onCreateOptionsMenu(menu);
}
if you want to split the actionBar in the bottom of the screen you can use
android:uiOptions=”splitActionBarWhenNarrow”
in your activity in the manifest
hope it helps

Related

Appcompat three dot menu not displayed on Android < 3

I would like to display three dot menu in my app also on devices with android lower than version 3.0.
But on devices with Android version < 3 is menu displayed only after menu button pressing.
I tried to find any wotking solution for this but none from them working from me.
What is most easy way how to solve it on all devices?
Im using appCompat_v7_3
Many thanks for any advice.
Here is code of menu and activity.
menu main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/last_position_menu_btn"
android:icon="#drawable/ic_drawer"
android:title="#string/last_positions"
android:showAsAction="always"/>
<item android:id="#+id/settings_menu_btn"
android:icon="#drawable/ic_drawer"
android:title="#string/app_settings"
android:showAsAction="always"/>
</menu>
onCreateOptionMenu from main Activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
return super.onCreateOptionsMenu(menu);
}
Your 3.0 device has a hardware menu button. Android does not display the overflow icon when there is a hardware menu button present.
See this question or the documentation.

How I can add two menu in ActionBar Sherlock?

I used this guide to create the main application menu.
Next, I added a button (three dots on the left) and the button I want to add another menu. It is important that the menu was different for each fragment
Code of button:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.actlist, menu);
return true;
}
and xml file for this:
<menu xmlns:android=
"http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/act"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="title add"
android:titleCondensed="add">
</item>
If I try to add a menu, it replaces the main menu.
Thanks!
Items that don't fit in the actionbar are automatically added to the overflow, there is no need to create another menu. If you want to force the itmes to be in the overflow you can use android:showAsAction="never"

why I do not see my Icon in Android Option Menu?

I have the following code to generate a Menu Item:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu1"
android:icon="#drawable/ic_action1"
android:title="#string/foo" />
</menu>
I see the Item in the menu, but I can not see the icon. Whats wrong?
I dont want to use it as the following:
android:showAsAction="ifRoom|withText"
then I see the icon, but I dont want it to be in the Action Bar
When you are using the ActionBar / Holo theme, you won't see any menu item icons in the overflow menus, sorry.
I think you will get the old menu back when you apply a pre-Holo theme to your activity!
try something like this
onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your_menu, menu);
menu.getItem(R.id.your_item_id).setIcon(R.drawable.your_drawable_id);
}

ActionBarSherlock + split action bar menu + items with "withText" doesn't show text. How to fix?

I'm using ActionBarSherlock and I'm trying to add an options menu to the ActionBar.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_prev"
android:title="#string/menu_previous"
android:icon="#drawable/left_navigation"
android:showAsAction="always|withText" />
<item android:id="#+id/menu_next"
android:title="#string/menu_next"
android:icon="#drawable/right_navigation"
android:showAsAction="always|withText" />
</menu>
The icons are 32x32 pixels in the drawable-mdpi directory. When the ActionBar is split (portrait orientation), the icons show up but no text shows (plenty of room though). Long-pressing the icon Toasts the title. When the ActionBar is not split (landscape orientation), both the icons AND text show up as expected.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
Menu, MenuInflater, and getSupportMenuInflater() are all using the ActionBarSherlock implementations.
The 'Application' in the manifest declares:
android:uiOptions="splitActionBarWhenNarrow"
What can I do to make it show the title of each item when in portrait orientation?
Edit: Possibly relevant is that I'm running Android 4.0.4.
If you are using Android >= 3.0 ABS uses the system implementation of the actionbar, thus the behavior you see is correct. See #CommonsWare comment to the question as to why the behavior is that way.

define Action bar overflow items

If I define the following items for my action bar:
res/menu/action_menu.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="label"/>
<item android:title="label1"/>
<item android:title="label2"/>
<item android:title="label3"/>
<item android:title="label4"/>
</menu>
In my Activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_menu, menu);
return true;
}
Is there anyway to allow me define certain items move to action overflow part ? and how to do it?
P.S. Action overflow part is the right-most part of action bar which hide certain items like a popup menu.
It's the other way round. You need to explicitly tell the menu which ones you want in the ActionBar and which not by setting the appropriate flags
E.g.
<item android:id="#+id/refresh"
android:title="#string/refresh"
android:icon="#drawable/reload_button"
android:showAsAction="always"/>
Here android:showAsAction tells how to handle it. Options are
always
ifRoom
never
withText
You can or options together with the pipe symbol as "always|withText"
See the android docs for action bar for more documentation.
To add something to Heiko's answer about the "overflow menu" on the action bar, this only happens if you have items set as ifRoom and there is no room for them to be displayed. On the overflow menu they only appear with a title and no icon.
On Android 4.0, the overflow menu ("3 dot spinner") is only shown on devices that don't have the physical "menu" button. You can test this on an ADV setting the option Hardware Back/Home keys option to "no".

Categories

Resources