Settings for click events in some content color styles in Android TextView

Source: Internet
Author: User

Text content spannablestring SS = new Spannablestring (remindtitle), int stringlength = Ss.length ();//Set 0-2 character color Ss.setspan (new Foregroundcolorspan (color.red), 0, 2,spanned.span_exclusive_exclusive);//Set 2-5 of the word linked to the phone book, trigger dial Ss.setspan when clicked (new Urlspan ("tel:7758521"), 2, 5,spanned.span_exclusive_exclusive);//Set 9-11 of the characters for the network link, click on the Open page Ss.setspan (" Http://www.baidu.com "), 9, 11,spanned.span_exclusive_exclusive);//Set 13-15 characters to click, go to the text message interface, send the object to 10086ss.setspan ( New Urlspan ("sms:10086"), 15,spanned.span_exclusive_exclusive);//Bold Ss.setspan (new Stylespan (typeface.bold_ ITALIC), Stringlength-8,stringlength, spanned.span_exclusive_exclusive);//Set 0-2 character color Ss.setspan (new Foregroundcolorspan (color.red), stringlength-8,stringlength, spanned.span_exclusive_exclusive);//Italic Ss.setspan ( New Stylespan (Android.graphics.Typeface.ITALIC), 7, 10,spanned.span_exclusive_exclusive);//Underline Ss.setspan (new Underlinespan (), ten, 16,spanned.span_exclusive_exclusive);//spanned.span_exclusive_exclusiveactivity Jump First four words identifierYou can click the Ss.setspan (new Clickablespan () {///In the OnClick method to write the action to be executed when the link is clicked @overridepublic void OnClick (View widget) { Myapp.showtoast ("Click on the Disclaimer");}, Stringlength-8, Stringlength, spanned.span_exclusive_exclusive);// Use the Spannablestring object to set the content of the TextView control Tv_login_remind.settext (ss);//When you click a link, you must set the Movementmethod object for any action you want to perform tv_login_ Remind.setmovementmethod (Linkmovementmethod.getinstance ());

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Settings for click events in some content color styles in Android TextView

Related Article

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.