问题
I want to change text color for spinner without using textView
, I have already searched and found some tutorials Android: Where is the Spinner widget's text color attribute hiding?
but the main thing is they have used textView
.
<Spinner
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:entries="@array/Gender_Selection_arrays"
android:prompt="@string/Gender_Selection"
android:id="@+id/gendersel"
android:popupBackground="#67656c"/>
I know this code is not to change text color.
I have no idea how to do that,please guide me for doing the same.
Any help would be appreciable.
回答1:
I got solution for this, Create a new xml "spinner_style.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="fill_parent"
android:textColor="@color/Black" />
And fix this layout as your spinner style in your activity:
ArrayAdapter<String > gender_adapter = new ArrayAdapter<String> (getActivity(), R.layout.spinner_style,gender_spinner );
回答2:
Your Spinner
<Spinner
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:entries="@array/Gender_Selection_arrays"
android:prompt="@string/Gender_Selection"
android:id="@+id/gendersel"
style="@style/mySpinnerItemStyle"
android:popupBackground="#67656c"/>
mySpinnerItemStyle (Add this to styles.xml)
<style name="mySpinnerItemStyle" parent="Base.Widget.AppCompat.Spinner">
<item name="android:textColor">@color/my_spinner_text_color</item>
</style>
And finally in colors.xml
<color name="my_spinner_text_color">#FFFFFF</color>
mySpinnerItemStyle inherits from Base.Widget.AppCompat.Spinner and in that android:textColor attribute changes the color of the spinner text
来源:https://stackoverflow.com/questions/31515854/how-to-change-text-color-in-spinner-without-using-textview