首页 > 解决方案 > 解析数据时无法更改片段中显示消息的颜色

问题描述

我想更改我解析的文本的颜色。它取决于一个 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);

标签: javaandroidxml

解决方案


首先将值设置为 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);
    

推荐阅读