Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display of decimal numbers

Tags:

android

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:

enter image description here

I was wondering how to make something like that.

like image 312
0ne_Up Avatar asked Nov 24 '15 12:11

0ne_Up


2 Answers

Try to set HTML string to TextView

String text = "831<sup>69</sup>";
textView.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);
like image 166
Amy Avatar answered Sep 20 '22 12:09

Amy


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);
like image 34
Archit Goel Avatar answered Sep 18 '22 12:09

Archit Goel