我目前正在尝试根据从 neurosky 耳机读取的有关用户调解级别的数据来更改应用程序中 TextView 的背景。
基本上,如果调解级别低于 30/100,我希望 TextView 变为红色。
此功能当前可用。然而,一旦级别低于 30 并且 TextView 变为红色,即使调解级别上升,红色也不会消失。 (电平每秒测量一次)。我该如何解决这个问题?
当前代码:
case TGDevice.MSG_MEDITATION:
meditation.setText("Meditation: " + msg.arg1 + "\n");
if(msg.arg1<=30){
//if mediation level is low it turns red
meditation.setBackgroundColor(Color.RED);
}
break;
最佳答案
为什么不对 if 子句使用 else 部分,例如:
if(msg.arg1<=30){
//if mediation level is low it turns red
meditation.setBackgroundColor(Color.RED);
}else{
meditation.setBackgroundColor(Color.Your_color);
}
关于Android:根据输入更改 View 的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24494223/