【发布时间】:2014-04-18 12:09:26
【问题描述】:
我有一个小小的疑问,如果你能做到,我想知道。 目前,我有一个字符串,我检查是否使用“.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
}
问候!
【问题讨论】:
-
您只想将粗体设置为
Text one? -
@Raghunandan 是的,根据情况
-
您对 TextView 所做的更改(粗体、颜色)将影响该 TextView 中的所有字符串。听起来您正在寻找的是一个 SpannableString,它可以为字符串的某些部分设置跨度(例如粗体、颜色或字体)。
标签: java android string styles conditional