I'd really like my app to have a Spinner which stretches the entire length of my ActionBar, like the one in Gmail 4.0. Anyone know how to achieve this? Even if I set "match_parent" in the Spinner layout resource, it doesn't fill the entire bar. Preferably, I'd like to be able to have it fill the entire bar except for my action items, rather than using the split actionbar as well.
EDIT: see my answer below for an implementation using the built-in actionbar, or hankystyles' when using a custom view
If you have a TextView inside your Spinner, you can set the minEms to a high value. This is the easiest workaround I explored:
The spinner on my gmail app also spans the entire width of my action bar. This solution worked for me:
Where the spinner layout is like so:
I suspect there's a better solution to be had by overriding the default action bar navigation style like this but I couldn't immediately get that working.
Try setting the background of the spinner to an image file. The default background has caused me layout issues, but when I set it to my own png of a blank 1x1 pixle it filled my layout as I wanted. If that works you may have to create a custom image that works for you. I hope that helps.
Bit annoying that I've just done it, but here is a method of doing it using the built-in Spinner in the action bar. All you need to do is make your spinner item's main container a
RelativeLayout
and set its gravity to fillHorizontal, like so:And initialising the Adapter as so:
which then gives the required spinner spanning the entire actionbar (except for the action buttons):