Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change spinner dropdown item text color and text size

I'm using android databinding and as part of that, I have a spinner with items (array declared in strings.xml) as

android:entries="@string/items"

Now I would like to change the text color and size of the dropdown items. I want to do this with out creating a separate layout for item and using it through java (passing the item layout to array adapter and setting that adapter to the spinner).

I tried many ways and searched everywhere but didn't find appropriate solution.

Any help is appreciated.

like image 965
Vamsi Avatar asked Nov 19 '25 02:11

Vamsi


1 Answers

You should use android.support.v7.widget.AppCompatSpinner.

 <android.support.v7.widget.AppCompatSpinner
                    style="@style/Widget.AppCompat.Spinner.Underlined"
                    android:theme="@style/Spinner"
                    android:entries="@array/special_fx_arrays"
                    android:textSize="@dimen/text_size_normal"/>

Here the style to put in styles.xml

<style name="Spinner" parent="Widget.AppCompat.Light.DropDownItem.Spinner">
        <item name="android:paddingStart">0dp</item>
        <item name="android:paddingEnd">0dp</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:backgroundTint">@color/red</item>
        <item name="android:textSize">14sp</item>
</style>
like image 161
Khemraj Sharma Avatar answered Nov 22 '25 05:11

Khemraj Sharma