I want to display 3½
on android text view. I tried doing it with unicode but no luck. Please see my code below. Can anyone please help.
additionalInfoString = additionalInfoString.replace("½",<sup><small>½</small></sup>);
You need to use HTML format to show fractions
tv.setText(Html.fromHtml("3<sup>1</sup>/<sub>2</sub>"));
Verify your HTML Text here.
As Html.fromHtml(String s)
method has been depreciated. Take a look at this answer SO Answer
You can use the html formatting of Android TextView. However you must add a extra space on the top and bottom to keep the fraction from being cut off.
SpannableStringBuilder text = new SpannableStringBuilder();
text.append("3");
text.append("\n");
text.append(Html.fromHtml("<sup>1</sup>/<sub>2</sub>"));
text.append("\n");
P.S. : The above code is not tested (just a hunch)
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