如何在微调器中更改所选项的字体颜色?
我可以更改所选项目的背景颜色,下拉项目的颜色等,但不能更改所选项目的文本颜色...我该怎么做?
我的代码是:这是我正在使用的微调器 - :
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="32dip"
android:background="@drawable/mybg"
android:divider="@drawable/list_divider"
android:drawSelectorOnTop="true"
android:popupBackground="#D3D5D3"
android:prompt="@string/activityy_prompt"
/>
Run Code Online (Sandbox Code Playgroud)
这是mybg.xml
<!-- <item android:drawable="@drawable/blue" android:state_pressed="false"/> -->
<!-- <item android:drawable="@drawable/back11"/> -->
<item android:drawable="@drawable/greenyellow1" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/greenyellow1" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/greenyellow1" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/greenyellow1" android:state_selected="true"/>
<item android:drawable="@drawable/back11"/>
Run Code Online (Sandbox Code Playgroud)
使用这些我无法改变selecetd项目的文字颜色......
我有一个带有几个选项的微调器,每个选项显示一个简单的字符串.最初,文本全是白色的.但是,如果用户选择一个选项(使其成为顶部显示的选项),我希望该文本变为红色.
我怎样才能做到这一点?
编辑:解决了
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
((TextView) arg1).setTextColor(Color.parseColor("#E3170D"));
}
Run Code Online (Sandbox Code Playgroud) 我正在使用微调器并想添加微调器 - 改变行为取决于状态(聚焦,按下)
示例项目在这里https://github.com/vovs/spinner_issue
我的代码:
activity_main.xml中
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:spinnerMode="dropdown"
android:dropDownSelector="@drawable/spinner_state" />
Run Code Online (Sandbox Code Playgroud)
spinner_state.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@color/black" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@color/red" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@color/red" />
<item
android:state_enabled="true"
android:drawable="@color/gray" />
</selector>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
Run Code Online (Sandbox Code Playgroud)
所以,如果我在模拟器Android 4.0.2 API 14中运行app并尝试选择一些项目或使用鼠标滚轮滚动没有任何效果,我在选择器中设置(当按下或滚动时 - 项目应该是红色的,但它是蓝色 - ICS颜色的默认值).
对于Android 2.2 API 8,当使用滚轮按下或滚动时(在这种情况下状态为聚焦)颜色为黄色[橙色](Android 2.2的默认颜色)
如何为微调器启用选择器?

我正在开发一个Android应用程序,并在我的应用程序中的许多地方使用Spinner.我想要的是更改所选微调器项目的背景颜色,以便可以轻松识别当前选择的项目.
我已经选中了这个链接设置选择的Spinner项目的背景颜色,但这样做会改变所选的textview背景颜色,但不要在下拉列表中更改它的颜色,我想在我看到时更改所选textview的背景颜色下拉列表.
我想更改列表中所选项目的颜色,而不是在微调器上,请参见下图.
非常感谢先进.