我想制作一个用特殊符号和数字着色字的功能。这样的事情:如果用户输入^2Hi ^3everyone! Hi = green . everyone = red.
,但仅当符号"^x"
存在时,(x =指定颜色的数字)。
然后我想用textview和html格式来设置颜色。
这样的事情:
int x;
TextView show = (TextView)findViewById(R.id.show);
//gen is my button to print the result in the textview
gen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String txt = tv.getText().toString();
//"+x+ doesnt work :s here i want to pu a int x between 0 and 9
StringTokenizer tokenizer = new StringTokenizer(txt,"^"+x+);
switch(x) {
case 1:
s = "red";
break;
case 2:
s = "green";
break;
default:
s = "white";
}
show.setttext(function to set text in html format)
}
}
抱歉,但我不明白要正确发布代码:s 谢谢:))'