Spinner widget style

By default my spinner widget creates a popup with radio button. I want to have a small elegant dropdown instead.

I saw it in one of my previous exercises and know that’s a matter of style. But how..

Let’s gather info.

1. This has a good tutorial on how to style a spinner. However they are talking about making image buttons. I’m ok with text buttons. What’s a link ? (sorry i missed).

2. recommendation  to change style from Theme.Light to one of these (in styles.xml)

 android:theme="@android:style/Theme.Holo.Light"

OR

 android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
Let's try. This caused crash on startup about "unable to combine title with custom title". I had this problem when integrating custom title bar. Grr. Yes I remember the solution was to use Theme.Holo. No go. 
3. while waiting found this:

<Spinner 
    android:id="@+id/my_spinner"
    ...
    android:spinnerMode="dropdown"/>

The available options are “dialog” and “dropdown”. This results in a dropdown style. But dropdown still has radio buttons, it’s a small elegant widget. Better but not good enough.

4. This post has a code sample for showing a dropdown in a target location. Seems as a good thing to  know about but I won’t try it now. http://stackoverflow.com/questions/13560432/android-change-spinner-dropdown-view

5. Trying adding style just to the spinner

style = “android:style/Widget.Holo.Light.Spinner” and removed  android:spinnerMode=”dropdown”

Well, it took my dropdown back to where I started. They were talking about parent style though. I don’t know how to set it.

6. Set  parent style

<style name="MyDropDownNav"   parent="android:style/Widget.Holo.Light.Spinner"> 
<item name="android:textColor">#ffffff</item> </style> 
7. Good find http://blog.stylingandroid.com/archives/297 blog about styling android  

Enouggh.. maybe all I want is to remove these radio buttons
1. http://stackoverflow.com/questions/1891809/android-spinner-how-to-remove-radio-buttons

2. adapterSpinner = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[]{"1", "2"});
adapterSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
or
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,
new String[]{"1", "2"}
); spinner.setAdapter(adapter); THISONE is a winner!!!!!!
plus android:spinnerMode="dropdown" in the resource file . Otherwise dialog shows in a middle of the screen without radio buttons. 

Now I have to see again people were talking about background color of the dropdown popup.
android:popupBackground="@color/gray"
is expected to solve it

Bye now.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s