我有一个小小的疑问,希望您能帮我解答一下。 目前,我有一个字符串,我检查是否使用“.contains(“String”);”的单词例如:
TextView tv = (TextView) dialog.findViewById(R.id.txtr);
for (int x = 1; x < 2; x++) {
tv.append("Text one\n");
tv.append("Text Two\n");
}
if(tv.getText().toString().contains("Text one")){
//Found
}else{
//Not found
}
我的问题是这样的。我可以做有条件的,如果您找到我正在查找的单词,则应用一种样式吗?
if(tv.getText().toString().contains("Text one")){
tv.setTypeface(null, Typeface.BOLD); //I found text. Apply text bold
}else{
//Not found
}
问候!
最佳答案
您需要使用SpannableString
。
下面所有#字符都设置为红色。你可以把它加粗
Create clickable link in text view in android
编辑:刚刚找到了使其粗体化的示例
Why doesn't my text show up with style when using SpannableStringBuilder?
关于java - 将样式应用于android中字符串的选定文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384031/