SoFunction
Updated on 2025-03-11

android:TextView simple way to set text style and hyperlink

This article describes the simple method of android:TextView to set text styles and hyperlinks. Share it for your reference, as follows:

Set the style of text in TextView (such as: color, italics, etc.), and you can set different styles for text at different locations (such as: set the characters with index ranges of 1-3 to black, and the characters with 2-6 to bold, etc.)

myFirstTextView = (TextView)findViewById();
("This is my first TextView, hey" ,);
Spannable sp = (Spannable) ();
//Set red background(new BackgroundColorSpan(), 3, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
(new StyleSpan(.BOLD_ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//Set italic(sp);

For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.