Error404 Error404 - 2 months ago 71
Android Question

Change color of the drop down arrow of Spinner in XML

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.

Answer

There are two ways to achieve that.

First Way (Simpler):

In your xml, make sure your spinner has an id. In this example, let's call the 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 your colors.xml in the values folder.

or

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(Color.parseColor("#AA7744"), PorterDuff.Mode.SRC_ATOP);

Second Way:

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

It is really great. It will generate custom drawables for you with your preferred color. Make sure you choose the theme as holo (or anything else you want) and select spinner.

Comments