简体   繁体   English

Html.toHtml() 未解析 BackgroundColorSpan(Android Lollipop)

[英]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.我正在为我的应用程序编写 api 21 支持,问题是 BackgroundColorSpan 没有被 Html.toHtml() 在此 Z8A5DA52ED126447D359E70C05721A 上解析。 Is there ways to solve this?有没有办法解决这个问题?

Spannable screenshot可扩展的屏幕截图

Api 21 - Html.toHtml(spannable) result: Api 21 - Html.toHtml(spannable) 结果:

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

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

<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: Gradle 设置:

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.我认为这个问题是由旧 api 上的程序使用不同版本的 html 模块引起的。 Well, my solution is to copy code of Html class to new file, fix errors and use it instead of original.好吧,我的解决方案是将 Html class 的代码复制到新文件,修复错误并使用它而不是原始文件。

Add this line in build.gradle :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)这里编辑了Html.class驱动器(不知道另一种方式来发布代码很长一段时间)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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