本文整理汇总了Java中android.text.SpannableStringBuilder.clearSpans方法的典型用法代码示例。如果您正苦于以下问题:Java SpannableStringBuilder.clearSpans方法的具体用法?Java SpannableStringBuilder.clearSpans怎么用?Java SpannableStringBuilder.clearSpans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.SpannableStringBuilder
的用法示例。
在下文中一共展示了SpannableStringBuilder.clearSpans方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getText
import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
/**
* @param context
* @param spannable
* @param title
* @return
*/
public static SpannableStringBuilder getText(Activity context, Spannable spannable, String title) {
if (spannable == null || spannable.length() <= 0) {
Log.e(TAG, "getText spannable == null || spannable.length() <= 0 >> return new SpannableStringBuilder();");
return new SpannableStringBuilder();
}
SpannableStringBuilder builder = new SpannableStringBuilder(spannable);
builder.clearSpans();// should clear old spans
URLSpan[] urls = spannable.getSpans(0, spannable.length(), URLSpan.class);
if (urls != null) {
for (URLSpan urlSpan : urls) {
if (urlSpan != null) {
MyURLSpan myURLSpan = new MyURLSpan(context, urlSpan.getURL(), title);
builder.setSpan(myURLSpan, spannable.getSpanStart(urlSpan), spannable
.getSpanEnd(urlSpan), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
}
}
return builder;
}
示例2: bind
import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
@Override
void bind(Context context) {
try {
CharSequence charSequence = Html.fromHtml(message.getMsgContent());
String msg = charSequence.toString();
if (msg.endsWith("\n\n")) {
charSequence = charSequence.subSequence(0, charSequence.length() - 2);
}
rich_tvmsg.setText(charSequence);
rich_tvmsg.setMovementMethod(LinkMovementMethod.getInstance());
CharSequence text = rich_tvmsg.getText();
if (text instanceof Spannable) {
int end = text.length();
Spannable sp = (Spannable) rich_tvmsg.getText();
URLSpan[] urls = sp.getSpans(0, end, URLSpan.class);
SpannableStringBuilder style = new SpannableStringBuilder(text);
style.clearSpans();// should clear old spans
for (URLSpan url : urls) {
MyURLSpan myURLSpan = new MyURLSpan(url.getURL());
style.setSpan(myURLSpan, sp.getSpanStart(url),
sp.getSpanEnd(url),
Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
rich_tvmsg.setText(style);
}
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError error) {
error.printStackTrace();
}
}
示例3: getView
import android.text.SpannableStringBuilder; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//其实评论一般都是文字,高级点的带有图片评论,光文字的话复用不复用就没什么大区别了
View view = null;
if(convertView!=null)
{
view = convertView;
}
else
{
view = LayoutInflater.from(context).inflate(R.layout.listview_item, parent,false);
}
ViewHolder holder = (ViewHolder) view.getTag();
if(holder==null)
{
holder = new ViewHolder();
holder.txt_comment = (TextView) view.findViewById(R.id.txt_comment);
view.setTag(holder);
}
//给相应位置的文字赋内容
if (name != null && name.size()!=0) {
StringBuilder actionText = new StringBuilder();
//谁回复
actionText.append("<a style=\"text-decoration:none;\" href='name' ><font color='#1468a3'>"
+ name.get(position) + "</font> </a>");
// 回复谁,被回复的人可能不存在。
if(toName.get(position)!=null&&toName.get(position).length()>0) {
actionText.append("回复");
actionText.append("<font color='#1468a3'><a style=\"text-decoration:none;\" href='toName'>"
+ toName.get(position) + " " + " </a></font>");
}
// 内容
actionText.append("<font color='#484848'><a style=\"text-decoration:none;\" href='content'>"
+ ":" + content.get(position) + " " + " </a></font>");
holder.txt_comment.setText(Html.fromHtml(actionText.toString()));
holder.txt_comment.setMovementMethod(LinkMovementMethod
.getInstance());
CharSequence text = holder.txt_comment.getText();
int ends = text.length();
Spannable spannable = (Spannable) holder.txt_comment.getText();
URLSpan[] urlspan = spannable.getSpans(0, ends, URLSpan.class);
SpannableStringBuilder stylesBuilder = new SpannableStringBuilder(text);
stylesBuilder.clearSpans();
for (URLSpan url : urlspan) {
FeedTextViewURLSpan myURLSpan = new FeedTextViewURLSpan(url.getURL(),
context,name.get(position),toName.get(position),content.get(position));
stylesBuilder.setSpan(myURLSpan, spannable.getSpanStart(url),
spannable.getSpanEnd(url), spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
holder.txt_comment.setText(stylesBuilder);
holder.txt_comment.setFocusable(false);
holder.txt_comment.setClickable(false);
holder.txt_comment.setLongClickable(false);
}
return view;
}