Html.fromHtml() 已弃用,有什么替代方案? [英] Html.fromHtml() is deprecated, what is the alternative?

查看:20
本文介绍了Html.fromHtml() 已弃用,有什么替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新到 SDK 版本 24,现在 Html.fromHtml() 已弃用.并且 Html 类有一个新的方法,带有一个名为 flag 的额外参数,但它的最小 API 是 24.

I updated to the SDK Version 24 and now Html.fromHtml() is deprecated. And the Html class has a a new method with extra parameter named flag, but it's minimum API is 24.

对于较低的 API 版本,此功能是否有替代方案?我不想为此使用 WebView.

Is there any alternative to this function to the lower API versions?. I don't want to use a WebView for this purpose.

推荐答案

要么:

  • 在所有 API 级别上使用 Html.fromHtml(String),或者,

在 API 级别 23 和更早的设备上使用 Html.fromHtml(String),在 API 级别 24 及以上的设备上使用 Html.fromHtml(String, int),使用 Build.VERSION.SDK_INT 找出您正在运行的设备的 API 级别

Use Html.fromHtml(String) on API Level 23 and older devices, and Html.fromHtml(String, int) on API Level 24+ devices, using Build.VERSION.SDK_INT to find out the API level of the device that you are running on

在这种情况下,已弃用"是提示寻找双参数方法,但单参数方法仍然有效并且(很可能)会在相当长的一段时间内这样做.

In this case, "deprecated" is a hint to go look for the two-parameter method, but the one-parameter method still works and (in all likelihood) will do so for quite some time.

这篇关于Html.fromHtml() 已弃用,有什么替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆