在我的Android应用程序,我有一个包含特定的词,所以我想显示在文本视图和特定的词应该是highlighted.Hope下面的图片会给你一个想法,整串的字符串。
我已经使用下列code要做到这一点,但它不工作。
code:
con是我的字符串,groupNameContent是文本字段。
的 con.replaceAll(arrGroupelements [groupPosition] [5],&所述;字体颜色='#CA278C'>中+ arrGroupelements [groupPosition] [5] +&其中; /字体取代。);
groupNameContent.setText(Html.fromHtml(CON));
解决方案
对于每个字,你可以使用:
的TextView TextView的=(的TextView)findViewById(R.id.mytextview01);
//使用循环来改变文字颜色
Spannable WordtoSpan =新SpannableString(局部彩色文本);
WordtoSpan.setSpan(新ForegroundColorSpan(Color.BLUE),2,4,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(WordtoSpan);
in my android application i have a string that contains a specific word so i want to display whole string in text view and the specific word should be highlighted.Hope following image will give you an idea.
I have used following code to do this but its not working.
CODE:
con is my string and groupNameContent is the text field.
con.replaceAll(arrGroupelements[groupPosition][5],"<font color='#CA278C'>"+arrGroupelements[groupPosition][5]+"</font>.");
groupNameContent.setText(Html.fromHtml(con));
解决方案
for each word, you can use:
TextView textView = (TextView)findViewById(R.id.mytextview01);
//use a loop to change text color
Spannable WordtoSpan = new SpannableString("partial colored text");
WordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(WordtoSpan);
上一篇:死锁澄清?死锁