Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Customizing the Spinner widget Look and Feel

Is it possible to change the color of the radio button in the Android spinner widget. By default it displays the green color for the radio button.

I need to change it to some other color, is it possible, and how?

like image 674
Vinayak Bevinakatti Avatar asked Jul 05 '10 07:07

Vinayak Bevinakatti


People also ask

What is set spinner show () method?

Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.

How do you make a clickable spinner?

Try removing the xml attribute android:clickable="true" from the Spinner widget. It could be that the entire spinner is registering the click event rather than the individual spinner items.

Who is the parent class of spinner?

Android Spinner class is the subclass of AsbSpinner class.


1 Answers

I know this is an old question now, but here goes...

You will need to create a custom Theme and apply it to the Activity with your spinner.

First, you need to create images for the checked/unchecked states of the 'new' radio, you could just pull the given images btn_radio_on.png and btn_radio_off.png from the sdk's res/drawable-* folder(s). Edit them to look how you want (such as changing color or whatever) and save off to your project.

Next, create a new xml file in your res/values folder, and add the following:

<resources>
    <style name="CustomSpinnerRadioTheme" parent="@android:style/Theme">
        <item name="android:spinnerDropDownItemStyle">@style/EditedRadio</item>
    </style>

    <style name="EditedRadio" parent="@android:style/Widget.DropDownItem.Spinner">
        <item name="android:checkMark">@drawable/edited_radio</item>
    </style>
</resources>

Then, create another xml file in res/drawable named edited_radio.xml, and it should contain the following:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="false" android:drawable="@drawable/btn_radio_off" />
    <item android:state_checked="true" android:drawable="@drawable/btn_radio_on" />
</selector>

just be sure to reference your edited images for the checked states. Then you just have to apply the CustomSpinnerRadioTheme to your Activity and run!

A good resource I found is Applying Styles and Themes especially the additional reference on Android Styles (styles.xml) and Android Themes (themes.xml)

like image 158
Kevin Dion Avatar answered Sep 20 '22 21:09

Kevin Dion