我有一个带有多个选项的微调器,每个选项都显示一个简单的字符串。最初,文本全是白色的。但是,如果用户选择一个选项(使其成为顶部显示的内容),我希望该文本变为红色。
我该怎么做?
编辑:已解决
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.
因此,您很可能为 Spinner 创建了 OnItemSelectedListener()。所以在 onItemSelected() 方法中,您可以简单地更改文本颜色。
伪代码:
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
TextView selectedText = (TextView) parent.getChildAt(0);
if (selectedText != null) {
selectedText.setTextColor(Color.RED);
}
}
希望对您有所帮助。
关于android - 选择项目时更改微调器的文本(非背景)颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15564760/