TextView Click the specified string to jump to TextView hyperlink effect

Source: Internet
Author: User

Online Search a lot of blog read is not exhaustive, each method of the use of the meaning of writing are not all, even the method of eight bad, so I also thick cheek to write down this effect bar.

Because this page uses MVP, so there will be a iview accumulation, this method naturally will @override


@Override public void Setbluetext (string zw_longtext, String zw_bluetext) {//"to become a unicom user, the default speed can be raised free of charge to 200k/s, and the validity period is longer!        Click on the Unicom User registration page to apply "; Remindlongwords = Zw_longtext + "click-through" + Zw_bluetext + "apply";//Display all strings//Draw Color Part code/* Spannablestringbuilde        R style = new Spannablestringbuilder (remindlongwords); Style.setspan (New Foregroundcolorspan (Getresources () GetColor (r.color.deepblue_wor d)), start, end, spannable.span_exclusive_inclusive);        Sets the color of the specified position text remindwords.settext (style);        Remindwords.setonclicklistener (this); *//need to listen for the range of click Start end int start = Zw_longtext.length () + 3;        int end = Zw_longtext.length () + 3 + zw_bluetext.length ();        1. You must create a new span spannablestring spstr = new spannablestring (remindlongwords); 2.NoLineClickSpan write the color and click event for the location Nolineclickspan Clickspan = new Nolineclickspan (wantupdkpresenter.factorydk MaiNmodel.zw_type, Getresources (). GetColor (R.color.deepblue_word));        3.span Help Top click Span Spstr.setspan (Clickspan, start, end, spanned.span_inclusive_exclusive);        4. Need to set down str remindwords.settext (SPSTR);    5. Set TextView can click Remindwords.setmovementmethod (linkmovementmethod.getinstance ()); }

Nolineclickspan is a class that inherits from Clickspan and overrides the color and click events with the following code:


/** * Created by AA on 2015/4/24. * Nolineclickspan is a class that inherits from Clickspan, overriding the color and click events, the code is as follows: */public class Nolineclickspan extends Clickablespan {    int type;    int showcolor;    Public Nolineclickspan (int type,int cl) {        super ();        This.type=type;        SHOWCOLOR=CL;    }    @Override public    void Updatedrawstate (Textpaint ds) {        ds.setcolor (showcolor);        Ds.setunderlinetext (FALSE); Remove underline    }    @Override public    void OnClick (View widget) {        //processhyperlinkclick (text);// Call        log.e ("onclick", "already clicked") when clicking the hyperlink;        Intent intent=new Intent (Widget.getcontext (), uniapplyactivity.class);        Intent.putextra ("type", type);        Widget.getcontext (). StartActivity (intent);    }}





TextView Click the specified string to jump to TextView hyperlink 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.