I'm using ActionBarSherlock in an app. The problem I'm having is that when the device is older and the action overflow is handled by the options menu at the bottom, I need to switch the icon to accommodate that. How can I tell if an action bar item is in the overflow or not? Is there a selector state I can use in the drawable for that?
Related
Per usual my ActionBar has a number of menu items that I set as app:showAsAction="never". So when user clicks on the overflow button, these items show up but they don't have icons. How do I force the icons to show? The answer at Is it possible to display icons in a PopupMenu? does not answer my question as it is concerned with the popup menu. When I tried to apply it to my case it shows all items not just the ones in the overflow. Also I am anchoring it in the toolbar as I don't know how to get the overflow view.
I don't think there is a simple way to toggle showing an icon in the action bar overflow menu. But I did find that someone was able to create a fully customized overflow menu:
http://keepsafe.github.io/2014/11/19/building-a-custom-overflow-menu.html
I have searched for Option menu and overflow Action menu, but did not get any difference in both.
Is there any difference or both are exactly same?
The option menu is used on Android 1.x/2.x devices, for apps that are not using an action bar backport (e.g., appcompat-v7).
The overflow menu in the action bar is used on Android devices that have an action bar, either the native action bar or a backport.
Menu items, such as those defined in onCreateOptionsMenu(), will go into an options menu on devices and apps that use it, or will go into the action bar on devices and apps that use one of those. Menu items not specifically designated to go into the action bar as toolbar-style buttons or other widgets will go into the overflow. Menu items that do not fit in the action bar will also go into the overflow.
Android uses the old options menu terms (e.g., onCreateOptionsMenu() instead of onCreateActionBarItems()) for backwards compatibility, so apps can be written to use the native action bar and still work, to some extent, on devices that lack an action bar.
There only exists one options menu. If the device has a menu key, then the overflow menu items appear when the key is pressed. On the other side, if the device has not menu key, then they appear on the action bar overflow icon.
Let me explain my current scenario.
I have a split action bar. From what I understand all action items will go to the bottom of the split action bar. I want to have some action items in the top action bar so I made a custom action bar by making an xml file for it.
In my onCreate, I have this to set up the top action bar...(custom_actionbar is an xml file I made.)
getActionBar().setDisplayOptions(
ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP
| ActionBar.DISPLAY_SHOW_CUSTOM);
View view = View.inflate(getApplicationContext(),
R.layout.custom_actionbar, null);
getActionBar().setCustomView(view);
So this works to set up the top of the action bar.
Now I am getting closer to my problem. I can currently get an action overflow icon in the bottom of the split action bar, but I want the icon to be at the top of the split action bar.
For a simple action bar it is possible to set the action overflow icon by doing android:showAsAction = "never" in the respective menu xml file.
HOWEVER, if I am doing a custom action bar for the top, I can not do this. This will only apply to the bottom action bar as all of the elements in the respective menu xml file will go to the bottom of a split action bar.
Does anyone know how I can get the action overflow icon to appear at the top of the split action bar or should I remodel everything in a different way? Like just have a normal action bar and then have some strip to hold image buttons at the bottom to mimic a split action bar? Or is there a way to get the elements in the menu xml file to go to the top of the split action bar?
Any Help is appreciated.
Thanks
By what i understand you want to have the overflow menu in the top action bar which is a custom xml file. You can actually mimic that overflow menu icon and the options list in the custom xml file if required. It is basically a hack to use popup windows with a list adapter to mimic the overflow menu behavior. Check the link: http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html
Hopefully this solves you problem.
So there is no real "good" way of having the action overflow button in the top of a split action bar menu. There are several ways that one could go about doing this.
Create a custom view for the top, have an image button that represents the action overflow menu icon and launch a pop up menu onClick to simulate the action overflow menu.
Create a regular (single) action bar and then create a custom view that will be at the bottom of the activity that will resemble the bottom of a split action bar. The action bar can get the action overflow menu if at-least one menu item is set to android:showAsAction = "never"
I personally went with option 2 because I could not find a suitable icon that represents the action overflow icon.
I am new to android.
How can i create option menu with out images like in the attached image? Do i need to use action bar or normal onCreateOptionMenu will do?
If you've developed your application for Android 3.0 (API level 11)
and higher, items from the options menu are available in the action
bar. By default, the system places all items in the action overflow,
which the user can reveal with the action overflow icon on the right
side of the action bar (or by pressing the device Menu button, if
available). To enable quick access to important actions, you can
promote a few items to appear in the action bar by adding
android:showAsAction="ifRoom" to the corresponding elements.
You can refer this doc for more detail.
Does anyone know how to add "menu" text under the dots menu icons in action bar?
Also, how can I make my option menu items to display the icon in Android 4.0?
You can't add text under the default menu icon in the 4.0 Action bar, you do however have two alternatives
1) You can create your own icon that includes the text 'Menu' (Unfavourable)
2) Create a custom menu item with the dots image and the properties so that the text appears next to it.
android:showAsAction="always|withText"
Take a look at The Android SDK Documentation on Action Bar to see how to create custom items and make them perform tasks.