0

In my app I use BackgroundColorSpan and print the result on TextView by using the Html.java. Here is a html sample string I try to print:

<html><body><p><span style=\"color:#000000;\"><span style=\"background-color:#0;\"><u>Test</u></span></span></p></body></html>

When I try to print, it looks so:

Print on TextView

This issue happens only when using the TRASPARENT color, other colors are printed/r well. It seems the TextView class does not support transparent color rendering. How can I handle that?

One more issue is that the BackgroundColorSpan overrides the highlight color when selecting the text. To this issue I found this post, but did not really help.

halfer
  • 19,824
  • 17
  • 99
  • 186
Mark Delphi
  • 1,376
  • 1
  • 11
  • 29
  • "It seems the Html class does not support transparent color rendering" -- `Html` does not render anything. `Html` converts HTML to a `Spanned` object, which in turn is rendered by `TextView`. – CommonsWare Jan 18 '21 at 22:53
  • @CommonsWare Yes, exectly. However, this could mean that the problem is in textview, is not? When it renders, then it somehow can't deal with when I comes to the transparent color. – Mark Delphi Jan 18 '21 at 23:14
  • "However, this could mean that the problem is in textview, is not?" -- that or `BackgroundColorSpan`, which is what `background-color` maps to. Your question is focused on `Html`, though, particularly in terms of the title. This may limit your answers. – CommonsWare Jan 18 '21 at 23:21
  • `#0` is not a valid color value. Hexadecimal colors should either be 3 or 6 characters long for RGB, or 4 or 8 characters long for RGBA (without the # of course). – Gergely Kőrössy Jan 18 '21 at 23:59
  • @GergelyKőrössy actually, that value is valid and even you can get it when calling `Color.TRANSPARENT`. However, if you take a dipper look inti this one `android:background="@android:color/transparent"`, this has the value `#00000000`. Both cases are not rendered. But if you put the above html string [here](https://jsonformatter.org/html-viewer) and run it, the result is exactly that one (both values are accepted) I try to achieve in Android on `TextView`. – Mark Delphi Jan 19 '21 at 08:26
  • The problem lies within the `Html` class that interprets the HTML source. No matter what you put in there, the alpha value will always be set 0xFF (fully opaque): `color | 0xFF000000` (Android uses ARGB). If the provided color string cannot be represented by an Integer, say #FFFFFFFF, it will not render the background (fully transparent). – Gergely Kőrössy Jan 19 '21 at 12:34

0 Answers0