【问题标题】:How to change text color in spinner without using textview如何在不使用 textview 的情况下更改微调器中的文本颜色
【发布时间】:2015-10-09 12:54:23
【问题描述】:

我想改变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"/>

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

我不知道该怎么做,请指导我做同样的事情。

任何帮助都将不胜感激。

【问题讨论】:

    标签: android android-layout android-spinner


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你的微调器

      <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 属性中更改微调器文本的颜色

      【讨论】:

      • 感谢您的回答,但您的回答仅适用于更改弹出背景颜色,而不是文本颜色。
      • 试试android:foreground而不是android:textColor
      • 也许这会解决你的问题stackoverflow.com/questions/6159113/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-20
      • 2013-08-21
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      相关资源
      最近更新 更多