Spinner Dropdown Menu Items (Android)

So, I have a counter, and I managed to change the color of the selected item, but I can’t change the color of the items in the drop-down menu

This is my spinner_layout.xml

<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="13sp" android:textColor="#33CCFF" /> 

and this is my styles.xml

 <resources> <style name="AppTheme" parent="android:Theme.Light" > <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem.Color</item> <item name="android:spinnerItemStyle">@style/SpinnerItem</item> </style> <style name="SpinnerItem.DropDownItem.Color" parent="@android:style/Widget.DropDownItem.Spinner"> <item name="android:textColor">#4FBDE8</item> </style> <style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem"> <item name="android:textColor">#4FBDE8</item> </style> </resources> 

Is there an XML way I can do this?

+6
source share
2 answers

Here is the solution I found in another stackoverflow

 <style name="Theme.NoTitleBar.WithColoredSpinners" parent="@android:style/Theme.NoTitleBar"> <item name="android:spinnerItemStyle">@style/SpinnerItem</item> <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item> </style> <style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem"> <item name="android:textColor">#00FF00</item> </style> <style name="SpinnerItem.DropDownItem" parent="@android:style/Widget.DropDownItem.Spinner"> <item name="android:textColor">#FF0000</item> </style> 

+3
source

When specifying a layout resource file for a counter, you must install it in two places.

  • New ArrayAdapter Announcement

     ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, categories); 
  • When setting the dropDownViewResource parameter to an array adapter.

     dataAdapter.setDropDownViewResource(R.layout.spinner_item_dropdown); 

Note that two different layout files were used. You can customize your views as follows by defining styles and using these styles as themes in their respective layouts.

 <style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem"> <item name="android:textColor">@color/white</item> <item name="android:background">@color/black</item> </style> <style name="SpinnerItem.DropDownItem" parent="@android:style/Widget.DropDownItem.Spinner"> <item name="android:textColor">@color/black</item> </style> 

Hope this helps.

+1
source

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


All Articles