TextView结合SpannableString使用大全

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);
 


你可能感兴趣的:(电话)