当选择一个项目更改微调的文本(而不是背景)颜色 [英] Change the TEXT (not background) color of a spinner when an item is selected
问题描述
我有一个微调几个选项,每个显示一个简单的字符串。最初,文字是全白。然而,如果用户选择一个选项(使其成为什么显示在顶部),我想是文本变成红色。
我怎样才能做到这一点?
编辑:解决:
公共无效onItemSelected(适配器视图<>母公司,观景,诠释POS,长ID){
((的TextView)ARG1).setTextColor(Color.parseColor(#E3170D));
}
如果用户选择一个选项(使其成为所显示的内容
在上面),我想该文本变成红色。
块引用>所以,你最有可能创建OnItemSelectedListener()为您的微调。因此,在onItemSelected()方法,你可以简单地改变文本颜色。
伪code:
公共无效onItemSelected(适配器视图<>母公司,观景,诠释POS,长ID){
TextView的selectedText =(TextView中)parent.getChildAt(0);
如果(selectedText!= NULL){
selectedText.setTextColor(Color.RED);
}
}希望它帮助。
I have a spinner with several options, each displaying a simple string. Initially, the text is all white. However, if the user selects an option (causing it to become what is displayed on top), I would like that text to become red.
How can I do this?
EDIT: solved:
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { ((TextView) arg1).setTextColor(Color.parseColor("#E3170D"));
}
解决方案if the user selects an option (causing it to become what is displayed on top), I would like that text to become red.
So you most likely created OnItemSelectedListener() for your Spinner. So in onItemSelected() method you can simply change text color.
Pseudocode:
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { TextView selectedText = (TextView) parent.getChildAt(0); if (selectedText != null) { selectedText.setTextColor(Color.RED); } }
Hope it helps.
这篇关于当选择一个项目更改微调的文本(而不是背景)颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!