Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change colour of small triangle on spinner in android

enter image description here

How can I change the colour of small triangle at the bottom right corner of spinner like shown in the image? It is showing default grey colour right now. like this

enter image description here

like image 405
Yawar Avatar asked Sep 18 '14 11:09

Yawar


People also ask

What are the spinners in Android user interface?

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.


2 Answers

The best and easiest solution:

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

Other solution (Thanks to Simon) if you don't want change all Spinners:

Drawable spinnerDrawable = spinner.getBackground().getConstantState().newDrawable();  spinnerDrawable.setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);  if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {     spinner.setBackground(spinnerDrawable); }else{     spinner.setBackgroundDrawable(spinnerDrawable); } 
like image 83
toni Avatar answered Sep 19 '22 18:09

toni


From Lollipop on, you can set the background tint on xml,

android:backgroundTint="@color/my_color" 
like image 31
Luis Avatar answered Sep 20 '22 18:09

Luis