2015-04-15 28 views
6

Vì nền bật lên của tôi có màu trắng, tôi cần thay đổi màu của bộ chia tách. Tôi đã cố gắng styling spinner theo cách sau nhưng nó không hoạt động:Thay đổi màu chia của Spinner

styles.xml

<style name="applicationTheme" parent="@android:style/Theme.Holo.Light"> 
    <item name="android:dropDownListViewStyle">@style/SpinnerStyle</item> 
</style> 

<style name="SpinnerStyle" parent="android:Widget.ListView.DropDown"> 
    <item name="android:divider">#0193DE</item> 
    <item name="android:dividerHeight">1dp</item> 
</style> 

xml chính

<Spinner 
     android:id="@+id/year" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" 
     android:background="@drawable/apptheme_spinner_default_holo_dark" 
     android:layout_marginLeft="75dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     android:spinnerMode="dropdown" 
     style="@style/SpinnerStyle" 
     android:popupBackground="#FFFFFF" /> 

java

ArrayAdapter<Integer> adapter_year = new ArrayAdapter<Integer>(this, R.drawable.custom_spinner_holidays, year); 
    adapter_year.setDropDownViewResource(R.layout.custom_spinner_popup); 

custom_spinner_holidays.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    style="?android:attr/spinnerItemStyle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:singleLine="true" 
    android:textColor="@android:color/white" /> 

custom_spinner_popup

<?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:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:ellipsize="marquee" 
    android:singleLine="true" 
    android:textColor="#0193DE" /> 

Tôi có thể chỉ cần kết hợp tất cả những thành một?

+0

tôi vẫn đang chờ đợi một câu trả lời hoàn hảo .. Không có gì dường như làm việc :( –

+0

bất cứ ai có thể giúp tôi ra Tôi đang mắc kẹt ở đây! –

Trả lời

2

Bạn cần phải đặt chủ đề này trong file manifest của bạn như thế này:

<activity android:name="com.example.activity.Solution" 
     android:theme="@style/applicationTheme"> 
</activity> 
+0

cảm ơn bạn rất nhiều: D –

0

Có lẽ ý tưởng tốt nhất là làm máy quay của riêng bạn và bạn có thể tạo kiểu theo cách bạn muốn. Hãy xem trong các chủ đề tiếp theo nó rất hữu ích cho tôi.

How to customize a Spinner in Android

+0

Vấn đề thực tế của tôi là phong cách không được áp dụng trên spinner.Không có lỗi thời gian chạy. Tại sao điều đó lại xảy ra? –

+0

Có thể bạn quên đặt phong cách của mình trong hoạt động của mình? Http: // stackoverflow. com/questions/4569751/how-to-show-divider-between-spinner-items/10177016 # 10177016 – acostela

Các vấn đề liên quan