Search code examples
androidandroid-actionbarandroid-spinnerandroid-theme

How to change color of text in ActionBar Spinner drop-down?


In my theme file, I have the following code to change the colors of the spinner's drop down:

<resources>
    <style name="AppBaseTheme" parent="android:Theme.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:dropDownListViewStyle">@style/DropDownListView</item>
    </style>

    <style name="DropDownListView" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
        <item name="android:background">@color/white</item>
        <item name="android:textAppearance">@style/CustomActionOverflowDropDownText</item>
    </style>

    <style name="CustomActionOverflowDropDownText" parent="@android:style/Widget">
        <item name="android:textColor">@color/black</item> <!--This does not work-->
   </style>
</resources>

However, the text color isn't changing. Is there any way to get around this?


Solution

  • I just found out how to do it by overriding getDropDownView in the ArrayAdapter:

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        TextView text = (TextView) view.findViewById(android.R.id.text1);
        text.setTextColor(Color.BLACK);
        return view;
    }