This is work perfect
val htmlContent = "<p><span style=\"background-color: #008080;\">Heloo This is new <span style=\"color: #0000ff;\">document</span> <span style=\"background-color: #ffffff;\"> TEXTT HHHH<strong>Hhhhhhhh</strong>hhhhhhhhhhhhh</span></span></p>\n" +
"<h1><span style=\"background-color: #008080;\"><span style=\"background-color: #ffffff;\">TEst dfsdf </span></span></h1>"
But When I trying to set this below Html content not working in android but in ios work perfectly
<p style="text-align:left;"></p>
<p style="text-align:justify;"><span style="color: rgb(250,197,28);background-color: rgb(255,255,255);font-size: 14px;font-family: Open Sans;"><strong>Yellow </strong></span><span style="color: rgb(0,0,0);background-color: rgb(255,255,255);font-size: 14px;font-family: Open Sans;"><strong>Ipsum</strong></span> <span style="color: rgb(0,0,0);background-color: rgb(255,255,255);font-size: 24px;font-family: Open Sans;">is simply </span><span style="color: rgb(209,72,65);background-color: rgb(255,255,255);font-size: 24px;font-family: Open Sans;">Red</span><span style="color: rgb(209,72,65);background-color: rgb(255,255,255);font-size: 14px;font-family: Open Sans;"> </span><span style="color: rgb(0,0,0);background-color: rgb(255,255,255);font-size: 14px;font-family: Open Sans;">text </span><span style="color: rgb(65,168,95);background-color: rgb(255,255,255);font-size: 14px;font-family: Open Sans;">greenthe </span><span style="color: rgb(0,0,0);background-color: rgb(255,255,255);font-size: 14px;font-family: Open Sans;">printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span></p>
<p style="text-align:left;"><br> </p>
Kotlin code
descriptionTextView.text = Html.fromHtml(
htmlContent, Html.FROM_HTML_MODE_LEGACY)
You should know all of HTML tags and attributes are not supported by android TextView and there are some limitations. For more information please look at the following questions:
1. Which HTML tags are supported by Android TextView?
2. Android textview html font size tag
In your case, the following attributes are not supported:
1. text-align
2. font-size
3. font-family
and also if need to set color, rgb(int, int, int)
value is unsupported as well.
Solution:
1. text-align
attribute only supports start
, end
and center
values.
2. You can use <small>
tag for smaller font size or <big>
tag for bigger font size.
3. You can use <font>
tag and face
attribute to set font face.
4. Use hex color code (For example #FF0000) instenad of rgb color code (For example rgb(255, 0, 0))
Important: If you have more than one attribute in an html tag, seperate them with ;[Space]
instead of ;
. Look at the following examples:
This exmaple doesn't work
<span style="color: #ff0000;background-color: #ffffff;">
RED
</span>
but this one works
<span style="color: #ff0000; background-color: #ffffff;">
RED
</span>
Android does not support all the HTML Tags.
It Depends on the HTML version in the Android device. For Batter output, you can use the web-view to get the desired output
You can refer to this blog so you will get an idea which tags supported by Android
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