0

Hi i want to show some symbol above other text like $ and % how to achieve this.Following is reference image

enter image description here

I have one textview in that i directly added it as:

<TextView
        android:id="@+id/month_txt"
        android:layout_marginTop="15dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/roboto_medium"
        android:text="$0.99/Month"
        android:textSize="24sp"/>

for bold font i reied like

month_txt.setText(Html.fromHtml("$0.99" + "<b>" + "/Month" + "</b>"));

now bold font is working but not able to get $ sign above actual price

But as expected it show all in same lline. How to achieve this like above image

  • Check this https://stackoverflow.com/questions/3543454/subscript-and-superscript-a-string-in-android – sanoJ Aug 19 '19 at 09:07
  • That's called superscript. The linked duplicate has several different methods to achieve that, both programmatically, or in XML with resources. – Mike M. Aug 19 '19 at 09:08
  • Yeah, you're almost there. Just add `` tags to your example: `Html.fromHtml("$0.99" + "" + "/Month" + "")`. You can add `` tags, too, if you want it a little shorter, as mentioned in one of the answers there. – Mike M. Aug 19 '19 at 09:11
  • ok using Html.fromHtml("X2 i can achieve this now one question how i can change font size for this 2 its very large (same as X). I want to reduce its size as comapred to X – user11945700 Aug 19 '19 at 09:16
  • I was just editing my above comment. You can add `` tags, too, as mentioned in [this answer there](https://stackoverflow.com/a/16362479). You can do that multiple times, btw, to get it to your desired size. – Mike M. Aug 19 '19 at 09:17
  • 1
    Hi Mike Thank you so much for your time and answer. Good day ahead – user11945700 Aug 19 '19 at 09:56

0 Answers0