2012-08-22 7 views
5
thanh

Hành động của tôi hiện là như thế này:Làm cách nào để thay đổi màu chữ của IcsSpinner trên ActionBarSherlock?

enter image description here

tôi muốn nó được như thế này:

enter image description here

bỏ qua các đường màu đen bên cạnh biểu tượng. Chủ yếu là những gì tôi muốn là để change the color of the text in the IcsSpinner to white

mã ngành của tôi là:

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

và custom_actionbar.xml của tôi là:

<?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> 

Tôi thậm chí còn muốn spinner là just left to the refresh icon. Giống như trong hình ảnh thứ hai.

Cảm ơn bạn

Trả lời

15

Bạn cần phải sử dụng getSupportActionBar().getThemedContext() như Context dụ trao cho các bộ chuyển đổi cho lạm phát bố cục. Điều này sẽ sử dụng bất kỳ chủ đề nào phù hợp để tăng cường các tiện ích bên trong thanh tác vụ thay vì chủ đề được đặt cho nội dung hoạt động của bạn.

+0

yeah đó giải quyết trong việc thay đổi màu sắc văn bản. cảm ơn rất nhiều. nhưng làm thế nào tôi có thể thay đổi vị trí IcsSpinner sang bên phải ??. như trong hình ảnh thứ hai –

+0

Bạn không thể thay đổi vị trí hiển thị hình ảnh. Nếu bạn cần kiểm soát nhiều hơn một thứ như thế, bạn phải sử dụng chế độ xem tác vụ tùy chỉnh. –

1

Chỉ cần để khen câu trả lời được chấp nhận: này làm việc cho tôi sau khi một số NullPointerException lạ trong khi cố gắng để tạo ra ArrayAdapter mới sử dụng constructor

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