Ensure Android's Overflow button does not come up on my Actionbar - android

I implemented the overflow button myself using the following base XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="Settings"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always">
<menu>
<item
android:id="#+id/action_logout"
android:title="Log out"
android:showAsAction="never" />
<item
android:id="#+id/action_offer_advice"
android:title="Advice"
android:showAsAction="never" />
</menu>
</item>
<item
android:id="#+id/action_create"
android:title="Create"
android:icon="#drawable/ic_action_new"
android:showAsAction="always"/>
</menu>
I did this because I want the Overflow button to be on every Android device regardless of a physical menu button. I opted for this over the hacky solution offered many times across Stackoverflow. That being said, I'm a bit fuzzy with ActionBars and I want to be positive that Android's default overflow won't show up for users that don't have a physical menu button. It would be very awkward to have my implementation of the overflow button with Android's default one right next to it.
Am I worrying over nothing? Is this a legitimate concern? If it is a legitimate concern, what could I do to handle that?

Personally I would say that this is not a concern. There are many apps native to the Android operating system (ex. the gallery app) that show the overflow menu despite the device having a physical menu button.
Another situation you may not have considered is the possibility that the user's menu button is not functional on the device, causing your action bar tidying to become a problem.
There is undoubtably a way to achieve this, but what you're trying to achieve may cause more problems than solve.

Related

How to prevent ActionBar SearchView button from disappearing

I have been having a lot of trouble trying to fix this one and couldn't find any solutions for this anywhere.
Currently I have the following ActionBar option menu
<?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/action_search"
android:icon="#drawable/ic_search"
android:title="#string/menu_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<item
android:id="#+id/action_sort_by"
android:title="#string/sort_by"
app:showAsAction="never" />
<item
android:id="#+id/action_refresh"
android:title="#string/action_refresh"
app:showAsAction="never" />
</menu>
And everything works perfectly fine except if the options menu is opened while the search option is also opened:
The target layout as expected
The search option opened
This is the step that causes the problem, as you can see the Search option is now in the menu
Because of the previous step the search button is gone when closing the menu and the search option
If I don't open the options menu while the search option is also opened then everything works perfectly well, however this is something that cannot be expected for users to do and they might open the menu with the search options opened, leading to the search icon to disappear, resulting in a very problematic user experience.
How can I fix this, how can I prevent this problem from happening while keeping that same layout? Search icon visible, everything else in the 3 dots options menu.
To always show the search icon, simple change app:showAsAction="ifRoom|collapseActionView" to app:showAsAction="always|collapseActionView"

Android Action Bar actions not showing all options, or in middle of UI, and other problems

I cannot get my action bar to work right at all. There's way too many crazy examples to run through, but I have encountered things like the action bar overflow bottom showing up halfway down the UI in 4.0.3 (I'm using android:uiOptions="splitActionBarWhenNarrow"), to clicking item A yet item B showing as the selecting item in OnOptionsItemSelected(MenuItem), or not showing them all.
Not trying to do anything crazy. I just want a refresh icon, info icon, share icon to show up and then 2 extra options to show up from clicking the dotted overflow icon. But I cannot get it to work consistently. I need to support 4.0+.
Here's what I have right now. I have slaughtered the menu xml while pulling my hair out, but maybe someone can shed some light on what I must be doing horribly wrong?
This current xml causes the bottom split action bar to sit right in the middle for the 4.0.3 AVD:
<item android:id="#+id/action_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/action_refresh"
android:showAsAction="always" />
<item android:id="#+id/action_info"
android:icon="#drawable/ic_action_about"
android:title="#string/action_info"
android:showAsAction="always" />
<item
android:id="#+id/menu_item_share"
android:showAsAction="ifRoom"
android:title="#string/action_share"
android:actionProviderClass="android.widget.ShareActionProvider" />
<item
android:id="#+id/action_category"
android:showAsAction="never"
android:title="#string/action_category" />
<item
android:id="#+id/action_about"
android:showAsAction="never"
android:title="#string/action_about"/>
Seems like the share action provider was cause of most the issues. Just using an icon with click handler that builds a share Intent instead.
Similar issue:

how to start placement of action buttons from the left in action bar

I am new to android development. Hence, I'm still in the getting-the-hang-of-it mode. I have started off my app by creating an xml file in the res/menu folder, the code for which is shown below. I need help with is placing the first (add) button in the left hand corner, where the title bar is supposed to be located, followed by the remove button in the centre, and finally the overflow menu in the last third. These three entities should be evenly spaced out. Additionally, I have managed to get rid of the app name and icon from the left hand corner.
Any help will be much appreciated.
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<item android:id="#+id/setting"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
<item android:id="#+id/add_contact"
android:title="#string/action_add"
android:orderInCategory="1"
android:showAsAction="ifRoom" />
<item android:id="#+id/remove_contact"
android:title="#string/action_remove"
android:orderInCategory="2"
android:showAsAction="ifRoom" />
This is what I want it to look like. It is a screen shot of the Nexus 4 contacts manager. However, I want buttons not tabs:
http://i.imgur.com/iDwUCJl.png
Current output: http://i.imgur.com/sQU3Jjq.png

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>

How to force overflow menu on android actionbar compat?

Android action bar compat
Is it possible? On older devices (pre 3.0) the items that don't fit the action bar are only shown when the menu key is pressed, I want these items to be grouped in the actionbar's overflow menu.
The action overflow menu is only available when there is no hard menu button available on the device. I found this stated in the Framework Topics under User Interface > Action Bar, check out the 3rd bullet here.
There is an action bar library written by Jake Wharton called ActionBarSherlock. Perhaps this is able to supply you with an action overflow menu style even when on older devices (which include a hard menu button), however I have not looked into this.
Edit: ActionBarSherlock 4.0 (currently a release candidate) has functionality built in to force action overflow. If you want to extend the ActionBarCompat example yourself, you could take a look on github to get an idea how Jake implemented it. I would suggest just looking into using his library all together, as it is very well done.
If you choose to use Jake's library, look into setting up the Activity theme as #style/Theme.Sherlock.ForceOverflow to force the overflow menu on older devices.
Edit2: Using ForceOverflow theme causes issues (example #1) on devices with hardware menu button. Thus, Jake Wharton is going to remove ForceOverflow in the future versions.
Okay, this is simple but hard to figure out.
You first need a menu item you want to use as the overflow inflater. Example
<item
android:id="#+id/a_More"
android:icon="#drawable/more"
android:showAsAction="always"
android:title="More">
</item>
Once you have your item, add a sub-menu containing your items you want in the overflow menu. Example:
<item
android:id="#+id/a_More"
android:icon="#drawable/more"
android:showAsAction="always"
android:title="More">
<menu>
<item
android:id="#+id/aM_Home"
android:icon="#drawable/home"
android:title="Home"/>
</menu>
</item>
On click this will inflate other items within. My application is using ActionBarSherlock 4.0 so before this will work for you, you will need to access the "SplitActionBar". (Will still work on default android Actionbar)
Here's how:
In your AndroidManifest.xml file, you need to add this code under the activity you need the overflow menu in.
Honestly it shouldn't matter if you have the actionbar split or not but I prefer it.
android:uiOptions="splitActionBarWhenNarrow"
NOTE: Your item that inflates your overflow menu MUST showAsAction="always"
Vwola! you have an overflow menu! Hope I helped you out. :)
Following LeviRockerSk8er's suggestion I've forced to have a overflow menu in the action bar like this:
This is the code for "menu.xml":
<item
android:id="#+id/web_clasica"
android:icon="#drawable/ic_action_web_site"
android:showAsAction="ifRoom"
android:title="#string/menu_web"
/>
<item
android:id="#+id/overflow_fijo"
android:icon="#drawable/ic_action_core_overflow"
android:showAsAction="always"
android:title="#string/menu_email"
>
<menu>
<item
android:id="#+id/email"
android:icon="#drawable/ic_action_new_email"
android:showAsAction="ifRoom"
android:title="#string/menu_email"
/>
<item
android:id="#+id/share"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="#string/menu_share"
/>
<item
android:id="#+id/about"
android:showAsAction="ifRoom"
android:icon="#drawable/ic_action_action_about"
android:title="#string/menu_about"/>
</menu>

Categories

Resources