Set hyperlinks, colors, and fonts for Android textview content

Source: Internet
Author: User

Color the content in double quotation marks:

Private void highlightsearchhint (spannable hintspan ){
String hint = hintspan. tostring ();
Log. I (TAG, "highlightsearchhint" + hint );
Int Index =-1;
Int start = 0;
Boolean foundstartquote = false;

Do {
Index = hint. indexof ("/" ", index + 1 );
If (foundstartquote & Index! =-1 ){
Foundstartquote = false;
Log. I (TAG, "highlight from" + (start + 1) + "to" + index );
/* Each setspan must use a new foregroundcolorspan object */
Foregroundcolorspan hintcolor = new foregroundcolorspan (color. parsecolor ("# 01a8ff "));
Hintspan. setspan (hintcolor, start + 1, index,
Spannable. span_exclusive_exclusive );
} Else if (! Foundstartquote & Index! =-1 ){
Foundstartquote = true;
Start = index;
}
} While (index! =-1 );
}

 

 

// Create a spannablestring object


Spannablestring sp = new
Spannablestring (
"Click Google link: italic ."
);

// Set a hyperlink between 2 and 3 Characters

Sp. setspan (New
Urlspan (
Http://www.google.com"
),
2
,
4
,

Spanned. span_exclusive_exclusive );


// Set italic on 7-8 characters

Sp. setspan (New
Stylespan (Android. Graphics. typeface. bold_italic ),
7
,
9
, Spannable. span_exclusive_inclusive );

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.