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