java - 解析数据时无法更改片段中显示消息的颜色
问题描述
我想更改我解析的文本的颜色。它取决于一个 raddiobutton,它是我的代码中的一个枚举。我是android新手,感谢所有帮助!这是我的枚举:
enum curricularNote{LECTURE, LAB, OTHERS};
无论我运行它,它只会将我的消息着色为红色:
TextView tvMessage = view.findViewById(R.id.mesaj);
if(notes.getCurNote().toString().equals("Lecture"))
tvMessage.setTextColor(Color.GREEN);
else
if(notes.getCurNote().equals("Lab"))
tvMessage.setTextColor(Color.BLUE);
else
// else if(notes.getCurNote().equals("Others"))
tvMessage.setTextColor(Color.RED);
解决方案
首先将值设置为 textview 然后根据值设置颜色:
Textview t = (Textview)findViewById(R.id.tw_id);
t.setText(value);
if(value.equalsIgnoreCase("LECTURE")
t.setTextColor(Color.GREEN);
else if(value.equalsIgnoreCase("LAB")
t.setTextColor(Color.BLUE);
else if(value.equalsIgnoreCase("OTHER")
t.setTextColor(Color.RED);
推荐阅读
- scala - 在 scala 中声明 String* 类型的变量
- teamcity - 为什么 TeamCIty 构建失败并显示“因为它正在被另一个进程使用”,它是否并行构建?
- angular - 设置 observable 并在更改时更新
- reactjs - React.js 模块解析失败:
- npm - NPM 安装/Babel 或 Gatsby 问题后 Storybook 失败?
- docker - 使用 Docker 和 Rancher 的 RabbitMQ 在管理 UI 中产生“TypeError: Cannot read property 'name' of undefined”-errors
- javascript - 除非手动聚焦窗口,否则 document.write 不起作用
- assembly - x86 中的偏移运算符返回逻辑地址还是偏移地址?
- apache-kafka - Azure eventthub as kafka:主题授权问题
- typescript - 运算符 '===' 不能应用于类型 '"x"' 和 'y'。三元运算符