I want to implement this seek bar in my app. I have created a custom view for the same. The only problem I am facing is how to change the color of the text from black to white when the circular view goes over the text. The image showing the custom view
My onDraw method()
override fun onDraw(canvas: Canvas?) {
canvas?.save()
canvas?.drawCircle(thumbX + 20F, thumbY, thumbRadius, mThumbPaint)
canvas?.drawBitmap(drawTextBitmap(), 0F, 0F, Paint().apply {
isAntiAlias = true
})
}
drawTextBitmap method which draws the track of 1 2 3 4 5 .....
private fun drawTextBitmap(): Bitmap {
val h = height
val w = width
val conf = Bitmap.Config.ARGB_8888
val bmp = Bitmap.createBitmap(w, h, conf)
val newCanvas: Canvas? = Canvas(bmp)
//newCanvas?.drawColor(Color.GREEN)
val initialOffsetX = paddingLeftCustom + thumbRadius
//newCanvas.drawColor(Color.BLACK)
for (i in 1..10) {
val textPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG)
textPaint.color = Color.BLACK
textPaint.textSize = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
20f,
resources.displayMetrics
)
.toInt().toFloat()
textPaint.textAlign = Paint.Align.LEFT
val metric: Paint.FontMetrics = textPaint.fontMetrics
val textHeight = Math.ceil((metric.descent - metric.ascent).toDouble()).toInt()
textPaint.colorFilter = PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.DST)
val y = (textHeight - metric.descent) as Float
newCanvas?.drawText(i.toString(), initialOffsetX + (i - 1) * spaceBetweenTexts, y, textPaint)
}
return bmp
}
I am using Porter's Duff Concept. The issue I am facing is I want to blend the text color and the thumb color (Circular View) but on whichever view I apply my color filter to it takes the canvas color into consideration.