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!