In kotlin you can do:
- define your paint with the stroke style in the initialization block
class CustomView(context: Context, attrs: AttributeSet) : View(context, attrs) { private var ringPaint: Paint init { ringPaint = Paint() ringPaint.color = R.color.RED // Your color here ringPaint.style = Paint.Style.STROKE // This is the important line ringPaint.strokeWidth = 20f // Your stroke width in pixels } }
- draw your circle in the onDraw method using drawCircleFunction (centerX, centerY, radius, paint)
override fun draw(canvas: Canvas?) { super.draw(canvas) canvas?.drawCircle(width / 2.0f, height / 2.0f, (width - 10) / 2.0f, ringPaint) }
source share