1

I was able to set Color to the first item in the Spinner using the following line of code. But how to give color to the item other than the first item selected by the user.

    List<String> spinnerArray =getContacts();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
        this,R.layout.spinner_effect, spinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner contactSpinner = (Spinner) findViewById(R.id.SpinnerchooseContact);
    contactSpinner.setAdapter(adapter);

((TextView) contactSpinner.getChildAt(0)).setTextColor(Color.GRAY);
Cœur
  • 37,241
  • 25
  • 195
  • 267
neo
  • 126
  • 1
  • 13
  • similar: http://stackoverflow.com/questions/6159113/android-where-is-the-spinner-widgets-text-color-attribute-hiding – Blundell Jan 01 '17 at 21:20

1 Answers1

2

create a new xml file, named dropdown.xml, define you style in this layout

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    android:textColor="#aa66cc"/>

then set to it your adapter

adapter.setDropDownViewResource(R.dropdown);
Mubashar Javed
  • 749
  • 1
  • 5
  • 12