當前位置: 首頁>>代碼示例>>Java>>正文


Java SpannableStringBuilder.clearSpans方法代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:28,代碼來源:MyURLSpan.java

示例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();
    }

}
 
開發者ID:lennyup,項目名稱:react-native-udesk,代碼行數:33,代碼來源:MessageAdatper.java

示例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;
}
 
開發者ID:xzh1223,項目名稱:ReplyDemo,代碼行數:64,代碼來源:CommentAdapter.java


注:本文中的android.text.SpannableStringBuilder.clearSpans方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。