Change Spinner Separator Color

Since my popup background is white, I need to change the color of the counter divider. I tried styling the counter like this, but it doesn't work:

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> 

main xml

 <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" /> 

Is it possible to combine all this into one?

+6
source share
2 answers

You need to put this theme in the manifest file as follows:

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

Maybe the best idea is that he makes his own counter, and you can style it the way you want. Take a look at the next thread, it was so useful for me.

How to set up Spinner in Android

0
source

Source: https://habr.com/ru/post/985159/


All Articles