Android: Where is the Spinner widget's text color attribute hiding? Android: Where is the Spinner widget's text color attribute hiding? android android

Android: Where is the Spinner widget's text color attribute hiding?


I think it's probably this bit in styles.xml

<style name="Widget.TextView.SpinnerItem">    <item name="android:textAppearance">@style/TextAppearance.Widget.TextView.SpinnerItem</item></style><style name="Widget.DropDownItem.Spinner">    <item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item></style>

-= EDIT =-Here's the result:enter image description here

and here's how it's done:

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="MooTheme" parent="android:Theme">        <item name="android:spinnerItemStyle">@style/MooSpinnerItem</item>    </style>    <style name="MooSpinnerItem" parent="android:Widget.TextView.SpinnerItem">        <item name="android:textAppearance">@style/MooTextAppearanceSpinnerItem</item>    </style>    <style name="MooTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">        <item name="android:textColor">#F00</item>    </style></resources>

Then just add this to the application tag in your AndroidManifest.xml

android:theme="@style/MooTheme"


Yeah CaseyB is correct.

Here's how I set the spinner text color, a little simple example:

styles.xml

    <style name="Theme.NoTitleBar.WithColoredSpinners" parent="@android:style/Theme.NoTitleBar">        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>        <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>    </style>    <style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">        <item name="android:textColor">#00FF00</item>    </style>    <style name="SpinnerItem.DropDownItem" parent="@android:style/Widget.DropDownItem.Spinner">        <item name="android:textColor">#FF0000</item>    </style></resources>

Then in your manifest:

<application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/Theme.NoTitleBar.WithColoredSpinners" >

The text on the outside of all your spinners will now be Green and the text on the dropdowns will be red.


I did this using another simple technique,

copy the simple_spinner_item.xml and simple_spinner_dropdown_item.xml from Android res/layout folder and copy them in your project.

Then modify the following lines

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, Android.R.layout.simple_spinner_item);adapter.setDropDownViewResource(Android.R.layout.simple_spinner_dropdown_item);spinnerSubject.setAdapter(adapter);

as:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.simple_spinner_item);adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);spinnerSubject.setAdapter(adapter);

The rest is easy, you can now edit the simple_spinner_item.xml to edit the appearence of one visible item on the spinner widget, and edit the simple_spinner_dropdown_item.xml to change the appearance of drop down list.

For example,my activity layout contains:

<Spinnerandroid:id="@+id/mo_spinnerSubject"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:background="@drawable/spinnerset_background" />

and my simple_spinner_item.xml now contains:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/text1"android:layout_width="match_parent"android:layout_height="wrap_content"android:singleLine="true"android:textColor="@color/custom_white"android:textSize="16sp" />

and the simple_spinner_dropdown_item.xml looks like:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/text1"style="?android:attr/spinnerDropDownItemStyle"android:layout_width="match_parent"android:layout_height="?android:attr/listPreferredItemHeight"android:background="@color/custom_black"android:ellipsize="marquee"android:singleLine="true"android:textColor="@color/custom_white" />