[英]Color change in textview
我使用XML parser.in,必须根据来自API的值更改textview的颜色。
从api它将返回1或-1(对我而言,如果为1则意味着我必须将背景更改为绿色,否则将更改为红色)。
我怎样才能做到这一点。
简单...
TextView yourTextView = (TextView)findViewById(R.id.yourTextView);
int response = responseFromParse(); // your parser logic
if(response == 1){
yourTextView.setBackgroundColor(Color.GREEN);
}else{
yourTextView.setBackgroundColor(Color.RED);
}
这很容易:
if(API()==1)
textView.setBackgroundColor(R.color.black);
else
textView.setBackgroundColor(R.color.black);
如果returm值在字符串中,请尝试
TextView txt =(TextView) findViewById(R.id.textView01);
String k;
if(k.contentEquals("1")){
`txt.setBackgroundColor(Color.GREEN);`
}
else{
txt.setBackgroundColor(Color.RED);
}
尝试这个,
TextView txt= (TextView) findViewById(R.id.textview1);
int val=Integer.parseInt(txt.getText().toString());
if(val==1)
txt.setBackgroundColor(Color.GREEN);
else if(val==-1)
txt.setBackgroundColor(Color.RED);
TextView text_view =(TextView)findViewById(R.id.textView1);
int returnval= your_returnval();
if(returnval== 1){
text_view.setBackgroundColor(Color.GREEN);
}
else if(returnval== -1){
text_view.setBackgroundColor(Color.RED);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.