Can't change the text color with Android Action Bar drop-down navigation

Please forgive my necromancy but this really bugged me today and the solution is actually quite quick and requires no custom adapters or styling.

If you change the context in the SpinnerAdapter's constructor to use getActionBar().getThemedContext() rather than this it will show light text on a dark background that will match the Action Bar's style.

SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(getActionBar().getThemedContext(), R.array.action_list, android.R.layout.simple_spinner_dropdown_item);

I've worked out that I can alter the colors for the drop-down Navigation in code, by creating my own subclass of ArrayAdapter as follows:

public class myArrayAdaptor<T> extends ArrayAdapter<T> {

    public myArrayAdaptor(Context context, int textViewResourceId, T[] objects) {
        super(context, textViewResourceId, objects);
    }

    public static myArrayAdaptor<CharSequence> createFromResource(Context context, int textArrayResId, int textViewResId) {
        CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
        return new myArrayAdaptor<CharSequence>(context, textViewResId, strings);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return SetColourWhite(super.getView(position, convertView, parent));
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return SetColourWhite(super.getView(position, convertView, parent));
    }

    private View SetColourWhite(View v) {
        if (v instanceof TextView) ((TextView)v).setTextColor(Color.rgb(0xff, 0xff, 0xff)); // white
        return v;
    }
}

Then with the simple styles.xml

<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    </style>
</resources>

I can substitute the class myArrayAdaptor

SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item)

and the text color will always be white. But isn't there a simpler way of doing this using settings in the styles.xml file?


Java code

SpinnerAdapter adapter = ArrayAdapter.createFromResource(this,
        R.array.actions,R.layout.dropdown_textcolor);

// OnNavigationListener
OnNavigationListener callback = new OnNavigationListener() {

    String[] items = getResources().getStringArray(R.array.actions); 
    public boolean onNavigationItemSelected(int position, long id) {

        // Do stuff when navigation item is selected
        Log.d("NavigationItemSelected", items[position]); // Debug
        return true;
    }

};


ActionBar actions = getSupportActionBar();
actions.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actions.setDisplayShowTitleEnabled(false);

actions.setListNavigationCallbacks(adapter, callback);

Xml dropdown_textcolor.xml

<?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:textColor="@android:color/white"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:ellipsize="marquee"
    android:textAlignment="inherit"/>