2011.09.20(4)——— android SpannableString 文字处理

2011.09.20(4)——— android SpannableString 文字处理
参考: http://blog.csdn.net/jamin0107/article/details/6626678

super.onCreate(savedInstanceState);
        TextView txtInfo = new TextView(this);
        SpannableString ss = new SpannableString("红色打电话斜体删除线绿色下划线图片:.");
        ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new URLSpan("tel:4155551212"), 2, 5,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 5, 7,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new StrikethroughSpan(), 7, 10,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new UnderlineSpan(), 10, 16,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(Color.GREEN), 10, 15,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable d = getResources().getDrawable(R.drawable.icon);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
        ss.setSpan(span, 18, 19, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        txtInfo.setText(ss);
        txtInfo.setMovementMethod(LinkMovementMethod.getInstance());
        setContentView(txtInfo);

你可能感兴趣的:(android,SpannableString)