0

I'm playing around with TextPaint on Android. I'd like to draw text with a background color on a Canvas without drawing a Rect behind it. I thought bgColor would do this, but apparently not. And nothing is said about it in the doc.

Interestingly though, if I apply that paint to the paint of an EditText, the background color appears, sometimes. Not sure why, maybe some function similar to invalidate is called somewhere:

val editText = findViewById<EditText>(R.id.edit)
val paint = TextPaint().apply {
    textSize = 120f
    typeface = Typeface.DEFAULT
    bgColor = Color.BLUE
}
editText.paint.set(paint)

So actually, if you guys have any idea of what's happening in one case or the other, that would be very helpful!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Omar Aflak
  • 2,918
  • 21
  • 39
  • like this https://stackoverflow.com/questions/15609426/draw-text-inside-a-filled-rectangle-using-canvas-android? – hemen Jun 11 '20 at 11:17
  • yeah, basically a background color behind each letter, like you would have on any editor such as Google Doc. I can do it with a Rect that's no problem. I just can't understand this `bgColor` attribute. – Omar Aflak Jun 11 '20 at 11:24

0 Answers0