I've seen some Android apps display decimal numbers where the decimal part has a smaller font, even though they appear to be in a single TextView, like this:
I was wondering how to make something like that.
Try to set HTML
string to TextView
String text = "831<sup>69</sup>";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
Here's one way to do this in java file:
textview.setText(Html.fromHtml("<b>" + title + "</b>" + "<small>" + description + "</small>"));
OR
Use spans.
Example:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With