How to change the color of IcsSpinner text to ActionBarSherlock?

My action bar currently looks like this:

enter image description here

I want it to be like this:

enter image description here

ignore the black line next to the logo. Basically i wantchange the color of the text in the IcsSpinner to white

my activity code:

    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this,
            R.layout.sherlock_spinner_item, cities);
    listAdapter
            .setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
    setContentView(mViewPager);
    final ActionBar bar = getSupportActionBar();
    bar.setCustomView(R.layout.custom_actionbar);
    bar.setIcon(R.drawable.logo);
    bar.setDisplayShowCustomEnabled(true);
    IcsSpinner citySpinner = (IcsSpinner) (bar.getCustomView())
            .findViewById(R.id.city_spinner);
    citySpinner.setAdapter(listAdapter);

and my custom_actionbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="right|center_vertical"
    android:orientation="horizontal" >

    <com.actionbarsherlock.internal.widget.IcsSpinner
        android:id="@+id/city_spinner"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>

</RelativeLayout>

I even want a spinner to be just left to the refresh icon. As in the second image.

thank

+5
source share
2 answers

You need to use getSupportActionBar().getThemedContext()as an instance Contextfor an adapter to inflate layouts. This will use any theme suitable for inflating widgets inside the action bar, and not for the theme set for the contents of your activity.

+15
source

: NullPointerException ArrayAdapter

    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ArrayAdapter<CharSequence> adapter = 
        ArrayAdapter.createFromResource(actionBar.getThemedContext(),
        R.array.action_list, android.R.layout.simple_spinner_dropdown_item);
    actionBar.setListNavigationCallbacks(adapter, this);
    actionBar.setDisplayShowTitleEnabled(false);
+1

All Articles