Change color of the drop down arrow of Spinner in XML

AndroidAndroid LayoutColorsAndroid SpinnerAndroid Color

Android Problem Overview


As I wrote in my question, I want to change the color of the drop down arrow (the default arrow, not a custom arrow or something like that) of a Spinner in XML, but the problem is that I couldn't find anything to make reference to it from the XML.

Is it possible? If yes, how can I change the color?

Thanks in advance.

Android Solutions


Solution 1 - Android

There are three ways to achieve that.

1. Through code:

In your xml, make sure your spinner has an id. Let's say we have a spinner with id "spinner".

In your code, add the following in your onCreate():

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);

where red is your defined color in colors.xml in the values folder.

2. Through xml:

For API 21+:

<Spinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="@color/red" />

or if you use the support library, you can use:

<android.support.v7.widget.AppCompatSpinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="@color/red" />

3. Through drawables:

You can use this online tool: http://android-holo-colors.com

This will generate custom drawables for any view you want with your preferred color. Make sure you select spinner, then download the resources.

Solution 2 - Android

I'm surprised noone had pointed it out, but you can just subclass Widget.AppCompat.Spinner and change backgroundTint

<style name="Spinner" parent="Widget.AppCompat.Spinner">
        <item name="backgroundTint">@color/spinnerTint</item>
</style>

and apply it to the Spinner

<Spinner
    style="@style/Spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown" />

Solution 3 - Android

use backgroundTint attribute

<Spinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/white"
        />

if min_SDK < 21(Lollipop) you should use AppCompatSpinner

<android.support.v7.widget.AppCompatSpinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="@color/white"
        /> 

Solution 4 - Android

If (API 21+) {

you can use directly android:backgroundTint="@color/color", inside your Spinner:

<Spinner
   android:id="@+id/spinner"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:backgroundTint="@color/color" />

} else {

create your own style:

<style name="spinner_style" parent="Widget.AppCompat.Spinner">
        <item name="backgroundTint">@color/color</item>
</style>

then into Spinner:

<Spinner
   android:id="@+id/spinner"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   style="@style/spinner_style"/> 

}

Note: you can use the style method in all API's.

Solution 5 - Android

try this:

spinner_age.getBackground().setColorFilter(ContextCompat.getColor(this,
                R.color.spinner_icon), PorterDuff.Mode.SRC_ATOP);

Solution 6 - Android

<Spinner
            android:id="@+id/spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="#00000" />

Only works above API Level 21

Solution 7 - Android

Use this dependency for create a very nice and easy spinner and use "app:arrowTint="@color/green" to change the arrow color

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrancisco RomeroView Question on Stackoverflow
Solution 1 - AndroidHussein El FekyView Answer on Stackoverflow
Solution 2 - AndroidmewaView Answer on Stackoverflow
Solution 3 - AndroidMehrdad FarajiView Answer on Stackoverflow
Solution 4 - AndroidMahmoud AymanView Answer on Stackoverflow
Solution 5 - AndroidMr TView Answer on Stackoverflow
Solution 6 - AndroidShweta ChauhanView Answer on Stackoverflow
Solution 7 - AndroidAhmad ArslanView Answer on Stackoverflow