Date: 2018aug22
OS: Android
Language: xml
Keywords: ColorStateList
Q. State Color for a custom Spinner
In res/color/my_spinner.xml make:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
This is copied from the Android docs.
In your per-item layout which may look like this, reference the colors:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#fff"
>
<ImageView
android:id="@+id/spinner_playback_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<TextView
android:id="@+id/spinner_playback_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:padding="10dp"
android:textColor="@color/my_spinner" <!-- *** reference your colors --->
/>
</LinearLayout>