Above is the image of what I want to achieve using String.xml
There are three things
- '76' & '20' will be replaced dynamically using String.format
- '20' should be bold
- '20' should be bigger in size
I have tried all the solutions using Html.fromHtml class.
Following are the solutions which I have tried. I am able to make '20' bold but couldn't make the '20' bigger in size.
Following are the differet variations of String.xml which I have tried
<string name="points_data">Use %1$d points= <font size="30">₹ %2$d</font> in payment</string>
<string name="points_data">Use %1$d points= <font size="14"><b>₹ %2$d</b></font> in payment</string>
<string name="points_data">Use %1$d points= <font size="14"><b>₹ %2$d</b></font> in payment</string>
<string name="points_data"><![CDATA[Use %1$d points= <font size="60"><b>₹ %2$d</b></font> in payment]]></string>
<string name="points_data">Use %1$d points= <b><span style="fontSize='50'">₹ %2$d</span></b> in payment</string>
Following is the method I use for parsing above string
val formattedText = String.format(getString(R.string.points_data), 76, 20)
textViewPoints.text = HtmlCompat.fromHtml(formattedText, HtmlCompat.FROM_HTML_MODE_LEGACY)
I have came across following links while googling for solution but none of them is working for my case.
- https://developer.android.com/guide/topics/resources/string-resource
- Set TextView style (bold or italic)
- Html.fromHtml deprecated in Android N
I have tried all the possible solutions which I could think of but none of them is working. I don't know what I am missing to implement. If anyone knows how to achieve this scenarion or knows about a way to achieve this please provide some guidance regarding that.