Html.fromHtml obsolete for Android N +

3

In the Android 7.0 (API level 24) static method fromHtml() of the public class Html has become obsolete I do not know why, if they can tell me. Here's an example of how it was used:

tv.setText(Html.fromHtml("<h3>Título</h3><br><p>Aqui é feito a descrição</p>"));

Considering this, what would be its equivalent? How can I use fromHtml() for Android N +?

    
asked by anonymous 28.03.2017 / 06:48

1 answer

6

In fact Html.fromHtml (String source) > is now considered obsolete. This, however, does not imply that it can not be used. Because you have no other option, if you want the app to run in versions prior to N.

The method that replaces it is Html.fromHtml (String source, int flag) (1) .

The parameter flag must be passed one or more (separated by the operator or | ) of constants that class Html states.

Each of these flags indicates how html in source should be "interpreted" when constructing Spanned returned by the function.

For example, the constant FROM_HTML_SEPARATOR_LINE_BREAK_LIST indicates that text within <ul> elements will be by default separated from other texts by a newline .

(1) - Use the Html constant. FROM_HTML_MODE_LEGACY for pre-N behavior.

    
28.03.2017 / 12:29