I have 2 different backgrounds to the Action bar. One light and another dark. One for the default title and another for the CAB (when some of the elements are selected/activated).
I would like to have 2 different overflow when in those different states.
I tried the selector but couldn't find the state to represent when in CAB mode.
Any idea how to provide different overflow buttons?
On a more general note, where can I start exploring the Action Bar so I could find the answers myself instead of finding bits and pieces all over the inet? I would expect Google/Android to provide a starting point. I guess I just didn't find it.
Related
I'm trying to create a custom popup/drop down menu on Android where when I click the action button from action bar the list of overflow options will appear but in a different format (image on right instead of left, button, etc). I tried to find some question and the one close to this is this question but the answer is incomplete and lacks the explanation. Now what I tried so far is to replicate it but removed the DropDown class but nothing happens as expected. I also tried some ways using the xml menu but its just giving me the same result of image on left and text on right. I think setActionView also doesn't work the way I expected it. Hope someone can help me on this.
When in some apps, there are those 3 dots in the top right of the app, on the action bar (not the home buttons), which allow for more options. In my app I have on, but I do not know how to make it do a method when it is clicked. Do I use android:onClick="METHOD_NAME ? Or do I need to setup a button variable in my activity class and setup and onClickListener? I have already tried both but I may be doing something wrong.
That three dots are the menu in the action bar. They are always shown on devices without a menu key.
See also the documentation for more details.
Three dots are called Overflow(very aptly named) and to use them you need to use ActionBar which is the top long, horizontal bar showing icons, other buttons along with the Overflow button.
Now in some devices where there is no physical menu button you will always see Overflow button.
Go through Docs and tutorials related to ActionBar but keep one thing in mind that ActionBar is only available for devices with android above HoneyComb. For android devices below 3.0 such as GingerBread or Froyo you will have to use compatibility libraries, so that will be an additional task.
And most notable libraries for this purpose are ActionBarSherlock and AppCompat.
I want to make a action-bar drop-down-menu that shows items (icons) horizontally. Like this:
This is suppose to be a action-bar withe drop-down menu, where you can choose a color.
So it should show the icons (colors) horizontally and the icons should be clickable. Until now I have only managed to make a vertical list.
If possible I would like to do this in XML.
The ActionBar is not designed for such a use-case. The ActionBar buttons are meant to replace the old options menu that could be triggered with a separate hardware button on older devices (pre HC/ICS). The overflow button (the one with the 3 dots) that you've drawn in your sketch is used when there isn't enough room to show all buttons (the Android framework takes care of this automatically), so those will be grouped in the overflow menu. Overriding this behavior is a bad idea (if even possible).
Instead you should consider another approach: Add one ActionButton to the ActionBar that is meant to handle the color chooser. When this button is clicked the best solution is to show an AlertDialog (you can easily insert your on Views here that show the colors you want) because this will work best even if the button is hidden in the overflow menu.
Alternatively you could trigger a PopupMenu or implement some QuickAction to handle the color chooser (this will probably suck if your button is hidden in the overflow menu and will also lead to a very confusing UI).
Is there any way to check how many buttons are visible, and how many are hidden in overflow?
Because, like we all know, depending on the device, a different number of buttons fits in ActionBar.
Why do I need it? I'm trying to place an arrow which will point to a particular action button. And to place it correctly, I need to know if this button is hidden in overflow, or is 3rd from the right edge?
Is there any way to check how many buttons are visible, and how many are hidden in overflow?
I don't think so. AFAIK, isVisible() will return true for items in the overflow area, as that is tied to the separate "visibility" aspect of a MenuItem.
I'm trying to place an arrow which will point to a particular action button. And to place it correctly, I need to know if this button is hidden in overflow, or is 3rd from the right edge?
No, you would need to know the pixel coordinates of the button, which will vary based on a number of factors, above and beyond whether or not it is in the overflow area, such as actual screen density.
I was wondering if it were at all possible to have checkable icons in an action bar in ICS? Not with a check, but with a android:stateChecked property to play around with. I want it so when the user clicks on the icon, they enter a certain mode (and the background of the icon would be a bright color to let them know they are still in that mode), and when they click it again they are taken out of that mode. I've played around with some selector xmls but nothing has worked...Any ideas?
EDIT: I just learned that Checkable items cannot appear in main menus, they can only be in submenus. However, is there a way to still get the behavior of a checkable? It's easy enough to have a boolean like isInModeA, but is there a way to programmatically change the background/icon of an Action bar item?
There is a way to programmatically change the background/icon.
You can use ActionBar.setBackgroundDrawable, for instance, or setCustomView, or setIcon (found on the same page).
You may consider using a dropdown-like ActionProvider to provide e.g. a radio-button-like "on/off" rather than a checkbox.
One approach you could try is to keep the state saved in some variable and just display different items based on this state. Obviously, some of these items can change the state. You might look at doing this by implementing a custom action provider.