2012-08-22 44 views
5

我的行動吧,目前是這樣的:如何更改ActionBarSherlock上的IcsSpinner的文本顏色?

enter image description here

我希望它是這樣的:

enter image description here

忽略標誌旁邊的黑線。主要是我想要的是change the color of the text in the IcsSpinner to white

我的活動代碼:

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); 

和我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> 

我連想微調是just left to the refresh icon。就像第二張照片一樣。

謝謝

回答

15

您需要使用getSupportActionBar().getThemedContext()給出的適配器充氣佈局的Context實例。這將使用任何主題適用於在操作欄內對小部件進行充氣,而不是爲活動內容設置主題。

+0

是的,在改變文字顏色解決。非常感謝。但我怎樣才能將IcsSpinner的位置更改爲右側??。就像在第二張圖片 –

+0

你不能改變它的顯示位置。如果您需要更多的控制權,您必須使用自定義操作視圖。 –

1

只是恭維接受的答案:這個工作對我來說有一些奇怪的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);