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

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:)

Related

Items are directly added in overflow menu in Actionbar

I'm developing an application in which i need to show a button with an icon on action bar. I tried following but it directly adds in overflow menu. I want it on action bar.
I tried a few solution given here on stackoverflow but none of them worked for me. please tell me what i'm missing
here is xml file of menu.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_wishlist"
android:icon="#drawable/wish"
android:title="WishList"
android:orderInCategory="0"
app:showAsAction="ifRoom" />
</menu>
it Adds item named 'Wishlist' in overflow menu.
Theme i'm using is
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
thanks.
If you are using Theme.Holo.Light, that means that you are not using appcompat-v7 for the action bar, but instead you are using the native action bar. In that case, change app:showAsAction to android:showAsAction.

What does overflow mean in this case?

I came across this during my android training :
Specify the Actions in XML
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
This declares that the Search action should appear as an action button when room is available in the action bar, but the Settings action should always appear in the overflow. (By default, all actions appear in the overflow, but it's good practice to explicitly declare your design intentions for each action.)
what does overflow mean in this context? It seems to me some design construct. Please explain.
Thank you in advance.
Overflow is a menu item which groups menu items that are not immediately visible on the ActionBar in a separate menu which needs to be tapped to show the contents. Refer to the Action Bar documentation for more information.
In the image above, #3 represents the overflow menu. The documentation on Menus also has quite a lot of information about this.

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>

Android menu items are not showing up at once

I have two menu items: Settings and Exit. When I run my code, with both set to showAsAction:"always", none of them show up on the screen when I press the menu button on my phone. This also happens if I set both to "ifRoom". However, if I set one to "never", the other one will show up. How can I get both items to show up? I am running a ~3.5 inch android 4.1.2 phone. I am using the android:theme="#style/Theme.AppCompat" theme.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<group android:checkableBehavior="single">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="ifRoom|withText"
android:icon="#drawable/sun"/>
<item android:id="#+id/exit_the_app"
android:title="#string/options_exit_text"
app:showAsAction="ifRoom|withText"
android:orderInCategory="101"
android:icon="#drawable/night"/>
</group>
</menu>
This is the screen when both items are set to "always" or "ifRoom", no menu items show up:
This is the screen when settings is set to "never", the exit item shows up:
There seems to be enough room, so how do I make both items show up? Thank you.
When showAsAction is set to ifRoom or always the item is shown in the action bar instead of the overflow menu (only if there's room in the case of ifRoom). This is the expected behavior.
If you want them to both show up in the overflow menu, set showAsAction to never for both.
I suggest reading the documentation: http://developer.android.com/guide/topics/ui/actionbar.html

Getting the right icons for Action Bar (ActionBarSherlock) and Options Menu with Android Gingerbread

How do you manage Icons with ABS and Gingerbread? As you can see from the Screenshots, I have a menu item "Help", that sits in the action bar, when there's room for it. (when nothing is selected). The icon looks good so far. But when it moves into the options menu, I probably should use another icon for better visibility :)
How do you normally do that? Any ideas? This is my menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/new_button"
android:showAsAction="always"
android:title="new"
android:icon="#drawable/content_new_calendar"/>
<item
android:id="#+id/share_button"
android:visible="false"
android:showAsAction="ifRoom"
android:title="share"
android:icon="#drawable/social_share"/>
<item
android:id="#+id/help_button"
android:showAsAction="ifRoom"
android:title="help"
android:icon="#drawable/action_help"/>
</menu>
I know how to create different menus for various api levels, etc. But here, the same phone is showing the icon in the action bar and in the options menu. The simplest solution is to set android:showAsAction="never", but from user reviews I learned, that the App is difficult to understand (especially the Widget-Part), so I would love to have the help menu visible. Any ideas?
P.S. I know that the App is ugly and unfinished. It's work in progress and will be polished :)
Try using the force overflow option like so:
<item name="absForceOverflow">true</item>

Categories

Resources