androidhtmlkotlinfont-sizefromhtml

font size is not working when using from html


I have a textview in an Android application. I want to set the textview's value from HTML. For example, I get a value like this:

<span style="font-family:'Roboto-Regular'; font-size:13px; color:#383838 \">102,</span>
<span style="font-family:'Roboto-Regular'; font-size:11px; color:#383838 \">60 TL</span> 

and I want to set the textview's value using the fromhtml() method. The color tag is working perfectly, but the font-size tag is not working - I expect the text after the comma to be small, but the tag doesn't change the text size at all.


Solution

  • Html.fromHtml() does not handle arbitrary HTML, let alone arbitrary CSS. While it does support color in a style attribute (at least on modern versions of Android), it does not support font-size or font-family. You will need to handle those yourself by other means.