Android : BackgroundColorSpan adjust height or add a padding to it

on Thursday, September 11, 2014


I have an app where I am displaying multiple lines, and multiple paragraphs, of formatted text in a TextView. I am using SpannableStringBuilder for this purpose.


One of the things I want to do here is to be able to highlight the text. Now I have tried using BackgroundColorSpan, but in this case, the background on the text covers the complete line-height. I want it to cover only the text instead. There seems to be no apparent way to set a vertical padding or height on this span. Just the colour.


Secondly, I also tried subclassing ReplacementSpan and implementing a backgroundSpan of my own by drawing in the draw method of this class. But this doesn't seem to support multiline highlighting.


Can anyone tell me how I can go about achieving this highlighting functionality? Basically, I want it to work like an ebook reader, preferably the Kindle or the default Book reader on Android.


0 comments:

Post a Comment