androidstringspanned

Using <b> tag inside string resource android to put in canvas drawtext() method


In Android, I want to make particular text bold in a paragraph. I stored that paragraph in the string resource of my project.Now I need to use that string as an argument to Canvas, drawtext() method. Where it will draw the specified string and make the text bold where i specified it as Bold using tag <b>.

I tried adding bold tag <b> and retrieve it using Html.fromHtml(_),but not worked,Used gettext() and getString().

Still i can't find the answer. I want it as a string,but not to put in a text view.I have tried spanned text or character sequence Please get me a solution.


Solution

  • Actually the issue was, in the String resource if we write `<b>` its will be converted to string itself.
    And when Html.fromHtml() tries to convert they found no tags,
    So,
    
    For < we have to use  &lt;
    For > we have to use  &gt;
    For & we have to use  &amp;
    

    Retrieve the text as spanned text and pass it to drawtext(). It worked !! Anyway thanks for the efforts.