Android TextView to achieve text-to-picture mixing effect

Source: Internet
Author: User


Use TextView to achieve this effect, picture text mixed, text different color font. Call and hang up the browser and so on

The code is as follows:

@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Mytextview = (TextView) This.findviewbyid (R.ID.IMG_IV);
Create a Spannablestring object
Spannablestring sp = new spannablestring ("This sentence has Baidu hyperlinks, there are highlighting, so, or so, there are italic.");
Set up hyperlinks
Sp.setspan (New Urlspan ("http://www.baidu.com"), 5, 7, spanned.span_exclusive_exclusive);
Set highlight Style One
Sp.setspan (New Backgroundcolorspan (color.red), 19,spannable.span_exclusive_exclusive);
Set the highlight style two Sp.setspan (new Foregroundcolorspan (Color.yellow), 20,24,spannable.span_exclusive_inclusive);
Set italic
Sp.setspan (New Stylespan (Android.graphics.Typeface.BOLD_ITALIC), spannable.span_exclusive_inclusive);
Call
Sp.setspan (New Urlspan ("tel:4155551212"), 2, 5,spanned.span_exclusive_exclusive);
The picture shows in TextView.
drawable d = getresources (). getdrawable (R.drawable.ic_launcher);
D.setbounds (0, 0, d.getintrinsicwidth (), D.getintrinsicheight ());
Imagespan span = new Imagespan (d, Imagespan.align_baseline);
Sp.setspan (span, 0, 1, spannable.span_inclusive_exclusive);

Spannablestring Object Set to TextView
Mytextview.settext (SP);
Set TextView to click
Mytextview.setmovementmethod (Linkmovementmethod.getinstance ());
}

Android TextView to achieve text-to-picture mixing effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.