Submenu not showing on Android 2.3 - android

I have an application with a Navigation Drawer and using Action Bar Compat and one of the options has an action bar button with a sub-menu. It is working fine on Android 3.0 and UP but not so good for Android 2.3:
<item
android:id="#+id/overflowButton"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="#string/word_menu"
yourapp:showAsAction="always">
<menu>
<item
android:id="#+id/usedRemainingMenuItem"
android:title="#string/menu_remaining"
/>
</menu>
<item>
What happens is that the app starts and I click on the button and it is fine. Then I choose another option from the Navigation Drawer, go back, and that button is no longer showing the sub-menu when clicked (I get the button action click on code).

Related

How to access or show popup from android Recents build-in button

I am trying to show the popup from android third button also called 'Recents' button one like whatsapp. Here is my screenshot which I want to achieve.
Edit
Popup must show from the right most button click.
Can anyone help me how can I access that button.
The menu on your picture is called 'overflow menu' and it shows action bar items that don't fit into the action bar (there is not enough space for them). It's shown at the bottom of the screen because your device has Menu button (on Samsung phones the most left button at the bottom of the screen).
Please note that the menu pops up from overflow button (three dots) in the top right corner if your device doesn't have Menu button. Refer Action bar official guide.
You can add items to overflow menu by specifying android:showAsAction="never" in you menu.xml file. It would look like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/item0"
android:icon="#drawable/icn_info"
android:orderInCategory="1"
android:showAsAction="always"
android:title="Action bar item"/>
<item
android:id="#+id/item1"
android:orderInCategory="10"
android:showAsAction="never"
android:title="Item 1 in overflow"/>
<item
android:id="#+id/item2"
android:orderInCategory="20"
android:showAsAction="never"
android:title="Item 2 in overflow"/>
<item
android:id="#+id/item3"
android:orderInCategory="30"
android:showAsAction="never"
android:title="Item 3 in overflow"/>
</menu>
EDIT:
As you can see, my device doesn't have Menu button at the bottom, so my WhatsApp shows overflow button in Action bar and overflow menu is coming from there:
EDIT 2:
Now I get your point. However, overriding Recents button is highly discouraged because it causes bad user experience. Recents button is never used for showing menu, it is used for showing Recent apps / documents.
Also, some devices don't even have this button (e.g. some Samsung devices use long press on Home button to show Recents).

Action Bar for Android being replaced by Menu Button?

Not sure if this is the appropriate place for this question, but here goes. I'm following the android tutorial for creating apps and I'm finding some issues with the implementation of the menus in the action bar. (http://developer.android.com/training/basics/actionbar/setting-up.html). I am testing on my Samsung Galaxy S4.
I am making an App for Android 3.0 and above but when I follow those instructions, the menu doesn't appear in the action bar, but becomes visible only when I press the menu button. If I follow the Android 2.1 and above instructions, the menu buttons appear in the action bar, except the overflow menu which is activated by pressing the menu button.
What do I need to do for Android 3.0 and above to make the menu appear in the action bar? Or is this no longer the way it works and it is meant to appear using the menu button instead now?
In menu.xml use showAsAction="always"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_start"
android:showAsAction="always"
android:title="Start"/>
<item
android:id="#+id/action_signout"
android:showAsAction="always"
android:title="logout"/>
</menu>

Should my Activity have menu as well as Action bar icons?

I am developing an application of my own and was reading this: http://developer.android.com/guide/topics/ui/menus.html
It says:
Beginning with Android 3.0, the Menu button is deprecated (some
devices don't have one), so you should migrate toward using the action
bar to provide access to actions and other options.
My app is only targeting android 4.2+. Does that mean I should present the menu options as only action bar icons ? What if there is not enough room available ?
Items that do not fit in the action bar will automatically be relegated to the overflow menu. All you have to do is set the android:showAsAction="ifRoom" property in your xml for the menu item.
This basically tells the system that this menu item should be displayed as an action icon if there is room available. If not, it should be shown as an overflow menu item.
It means that there is no more hardware Menu Button. Your menu items will be showed in popup under "three-doted icon". In menu.xml you can configure everything:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_example"
android:title="#string/action_example"
android:showAsAction="ifRoom" /> <!-- attention -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
Read more here
If you need a lot of icons to be showed you can split ActionBar(second(bottom) menu bar will appear).
documantation of splitting
I hope mine explanation will be good enough:)

ActionBarSherlock collapseActionView

I'm having a problem when I try to set one item in my actionbar as always visible and 4 more icons as dropdown items with the following layout:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/search_movies"
android:icon="#drawable/action_search"
android:showAsAction="always"
android:title="Search"/>
<item
android:id="#+id/movies"
android:icon="#drawable/action_video"
android:showAsAction="collapseActionView"
android:title="Movies"/>
<item
android:id="#+id/theaters"
android:icon="#drawable/action_location_map"
android:showAsAction="collapseActionView"
android:title="Theaters"/>
<item
android:id="#+id/preferences"
android:icon="#drawable/action_settings"
android:showAsAction="collapseActionView"
android:title="Preferences"/>
<item
android:id="#+id/contact"
android:icon="#drawable/action_about"
android:showAsAction="collapseActionView"
android:title="Contact"/>
</menu>
The result is just the first item showing and the rest are not visible, not even as a dropdown. This is using ActionBarSherlock and a 2.3 Android device.
The question is, how can I get the icons to follow this layout:
EDIT:
The problem I had was because when you are using the actionbar with a device that has a "menu" hardware button the 3-dot dropdown does not shows off, the 4 other items are only displayed if you press the menu hardware button. Does anyone knows if this behaviour can be modified?
Hmmm, maybe I misunderstood, but if you wish to places those remaining four items into the overflow action menu (the 3-dot icon) then using android:showAsAction="never" instead of "collapseActionView" should do it.
...Tried a couple ways, but this did the trick:
Force overflow menu in ABS
I've met the same problem and my solution is quite simple. (I didn't use HoloEverywhere.)
The idea comes from the ABS sample project, whose drop-down menu can be displayed on pre-4.0 devices as well by using a submenu. So, my idea is using a submenu to disguise the 3-dot icon. Here's the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
SubMenu sub = menu.addSubMenu("More");
sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
sub.getItem().setIcon(R.drawable.ic_menu);
getSupportMenuInflater().inflate(R.menu.activity_main, sub);
return true;
}
Since the "More" menu doesn't have a MenuItem.SHOW_AS_ACTION_WITH_TEXT attribute, so the word "More"(or whatever you named) will actually not be displayed on the action bar. The only displayed icon R.drawable.ic_menu can be copied from ABS source code res/drawable-xxdpi folders named "abs__ic_menu_moreoverflow_normal_holo_dark.png", which is the so-called 3-dot icon. And the R.menu.activity_main is your menu xml.
It works!

Menu button is not present on ActionBar

I want to build in my application an ActionBar with a button that makes the role of the old hardware menu button. I'm working on 4.0.3 platform with min sdk=8. The problem is i don't have the menu button in ActionBar and always have to press on emulator menu button to show it. Don't know what to do, there is surely a trick.
Menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_settings"
android:icon="#drawable/ic_action_settings"
android:showAsAction="always"
android:title="#string/menu_settings"/>
<item android:id="#+id/menu_help"
android:title="Help">
</item>
</menu>
And prepare the menu in Java code like always:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
I want a button in Actionbar that shows that menu. Possible?
The problem is i don't have the menu button in ActionBar and always have to press on emulator menu button to show it. Don't know what to do, there is surely a trick.
Not really.
The overflow menu affordance will only appear in the action bar on devices that lack an off-screen MENU button. This will be true for most tablets and many phones that originally shipped with Android 4.0 or higher.
For devices that do have a dedicated MENU button, that is used to bring up the overflow menu.

Categories

Resources