android - How can I change the color of the selected spinner item using XML not Java? -
i have android spinner , dropdown colors working ok can't change text color of selected item using xml, not java. i've tried think of. below code:
 <android.support.v7.widget.appcompatspinner         android:layout_width="368dp"         android:layout_height="wrap_content"         android:entries="@array/test"         style="@style/dropdown_text"         tools:layout_editor_absolutey="0dp"         tools:layout_editor_absolutex="8dp"></android.support.v7.widget.appcompatspinner> here things i've tried style:
<style name="dropdown_text">     <item name="android:background">#000000</item>     <item name="android:textcolor">#ffffff</item>     <item name="android:textcolorprimary">#ffffff</item>     <item name="android:textcolorsecondary">#ffffff</item>     <item name="android:textappearance">@style/white_text</item> </style>  <style name="white_text">     <item name="android:textcolor">#ffffff</item> </style> the background color works fine not text color.
so how can change selected item text color?
thanks.
edit: know there tons of posts asking same thing, majority of them in java code want on xml. show styles have change i've tried suggestions , nothing has worked.
when populate spinner entries, appcompatspinner create arrayadapter , use android.r.layout.simple_spinner_item "selected" view. simple_spinner_item textview styled using spinneritemstyle.
<textview xmlns:android="http://schemas.android.com/apk/res/android"      android:id="@android:id/text1"     style="?android:attr/spinneritemstyle"     android:singleline="true"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:ellipsize="marquee"     android:textalignment="inherit"/> so, if want change text color in simple_spinner_item, you'll need supply own style spinneritemstyle. like: 
<style name="apptheme" parent="theme.appcompat.light.darkactionbar">     <item name="android:spinneritemstyle">@style/yourspinneritemstyle</item> </style>  <style name="yourspinneritemstyle" parent="widget.appcompat.textview.spinneritem">     <item name="android:textcolor">@android:color/white</item> </style> you use textappearance instead of textcolor.
results:

Comments
Post a Comment