I am using Html.fromHtml
to view html in a TextView
.
Spanned result = Html.fromHtml(mNews.getTitle());
...
...
mNewsTitle.setText(result);
But Html.fromHtml
is now deprecated in Android N+
What/How do I find the new way of doing this?
I am using Html.fromHtml
to view html in a TextView
.
Spanned result = Html.fromHtml(mNews.getTitle());
...
...
mNewsTitle.setText(result);
But Html.fromHtml
is now deprecated in Android N+
What/How do I find the new way of doing this?
You can use
to suppress inspection just for single statement but not the whole method.
Compare of the flags of fromHtml().
From official doc :
https://developer.android.com/reference/android/text/Html.html
I had a lot of these warnings and I always use FROM_HTML_MODE_LEGACY so I made a helper class called HtmlCompat containing the following:
fromHtml
You should use FROM_HTML_MODE_LEGACY
Code
For Kotlin
Call
The framework class has been modified to require a flag to inform
fromHtml()
how to process line breaks. This was added in Nougat, and only touches on the challenge of incompatibilities of this class across versions of Android.I've published a compatibility library to standardize and backport the class and include more callbacks for elements and styling:
While it is similar to the framework's Html class, some signature changes were required to allow more callbacks. Here's the sample from the GitHub page: