S
S
Sharombolla2015-09-23 20:59:02
Java
Sharombolla, 2015-09-23 20:59:02

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

2 answer(s)
A
aol-nnov, 2015-09-23
@aol-nnov

So ?
All answers here :)

O
Oleg Gamega, 2015-09-23
@gadfi

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 question

Ask a Question

731 491 924 answers to any question