当选择一个项目更改微调的文本(而不是背景)颜色而不是、文本、颜色、背景

由网友(长不过执念短不过善变)分享简介:我有一个微调几个选项,每个显示一个简单的字符串。最初,文字是全白。然而,如果用户选择一个选项(使其成为什么显示在顶部),我想是文本变成红色。 我怎样才能做到这一点?编辑:解决: 公共无效onItemSelected(适配器视图<>母公司,观景,诠释POS,长I​​D){   ((的TextView)ARG1...

我有一个微调几个选项,每个显示一个简单的字符串。最初,文字是全白。然而,如果用户选择一个选项(使其成为什么显示在顶部),我想是文本变成红色。

我怎样才能做到这一点?

编辑:解决:

 公共无效onItemSelected(适配器视图<>母公司,观景,诠释POS,长I​​D){   ((的TextView)ARG1).setTextColor(Color.parseColor(#E3170D)); 

}

解决方案   

如果用户选择一个选项(使其成为所显示的内容  在上面),我想该文本变成红色。

所以,你最有可能创建OnItemSelectedListener()为您的微调。因此,在onItemSelected()方法,你可以简单地改变文本颜色。

伪code:

 公共无效onItemSelected(适配器视图<>母公司,观景,诠释POS,长I​​D){   TextView的selectedText =(TextView中)parent.getChildAt(0);   如果(selectedText!= NULL){      selectedText.setTextColor(Color.RED);   }} 
pages文件背景颜色如何更改教程

希望它帮助。

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.

阅读全文

相关推荐

最新文章