简体   繁体   English

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

[英]How to change text color in spinner without using textview

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? 我想在不使用textView情况下更改微调器的文本颜色,我已经搜索并找到了一些Android教程:Spinner小部件的文本颜色属性隐藏在哪里?

but the main thing is they have used textView . 但主要的是他们使用了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. 任何帮助都会很明显。

I got solution for this, Create a new xml "spinner_style.xml" 我得到了解决方案,创建一个新的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 );

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) mySpinnerItemStyle (将其添加到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 最后在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 mySpinnerItemStyle继承自Base.Widget.AppCompat.Spinner ,并且android:textColor属性改变了微调文本的颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM