如何在不使用textview的情况下更改微调器中的文本颜色

时间:2015-07-20 11:54:30

标签: android android-layout android-spinner

我想更改微调器的文本颜色而不使用textView ,我已经搜索并找到了一些教程Android: Where is the Spinner widget's text color attribute hiding?

但主要的是他们使用了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"/>

我知道这段代码不会改变文字颜色。

我不知道该怎么做,请指导我这样做。

任何帮助都会很明显。

2 个答案:

答案 0 :(得分:10)

我得到了解决方案,创建一个新的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" />

并将此布局修改为您活动中的微调器样式:

   ArrayAdapter<String > gender_adapter = new ArrayAdapter<String> (getActivity(), R.layout.spinner_style,gender_spinner );

答案 1 :(得分:3)

您的微调器

<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 (将其添加到styles.xml)

<style name="mySpinnerItemStyle" parent="Base.Widget.AppCompat.Spinner">
    <item name="android:textColor">@color/my_spinner_text_color</item>
</style>

最后在colors.xml

<color name="my_spinner_text_color">#FFFFFF</color>

mySpinnerItemStyle 继承自 Base.Widget.AppCompat.Spinner ,并且 android:textColor 属性更改微调文本的颜色

相关问题