Answer the question
In order to leave comments, you need to log in
How to programmatically change the font options of a single character in Android Studio?
Hello dear colleagues. I am a beginner android developer. And in my very first application, I encountered such a problem: I need to programmatically change the font settings of one character in a word. That is, for example, in the word CITY, change the color of the last letter, size, make it "bold". I will be glad for any help! Yes, and I would like to know from you the name of a convenient book where all such questions can be found. Thank you in advance!
Answer the question
In order to leave comments, you need to log in
Example from the first line of Google
final SpannableStringBuilder sb = new SpannableStringBuilder("your text here");
// Span to set text color to some RGB value
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158));
// Span to make text bold
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
// Set the text color for first 4 characters
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// make them also bold
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
yourTextView.setText(sb);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question