简体   繁体   中英

Html.toHtml() is not parsing BackgroundColorSpan (Android Lollipop)

I'm writing api 21 support for my app, the problem is that BackgroundColorSpan is not parsing by Html.toHtml() on this api. Is there ways to solve this?

Spannable screenshot

Api 21 - Html.toHtml(spannable) result:

<p dir="ltr"><b>Title</b><br>
<font color ="#36393e">Content with backgroundColorSpan</font></p>\n

New api's - Html.toHtml(spannable) result:

<p dir="ltr"><span style="font-size:1,30em;"><b>Title</b></span><br>
<span style="color:#36393E;">
  <span style="background-color:#6AB3D0;">Content with backgroundColorSpan</span>
</span>
</p>

Gradle settings:

compileSdkVersion 29
targetSdkVersion 29
minSdkVersion 21

I think this problem is caused by the program on old api's uses a different version of the html module. Well, my solution is to copy code of Html class to new file, fix errors and use it instead of original.

Add this line in build.gradle :

// TagSoup
implementation group: 'org.ccil.cowan.tagsoup', name: 'tagsoup', version: '1.2'

Here's edited Html.class : drive (don't know another way to post code for a long time)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM