If you have a view such as a TextView where you need to set the background and border you can do it like this Kotlin code:
val view = findViewById(R.id.miTextView) as TextView
val borderColor : Int = Color.GRAY,
val backgroundColor : Int = Color.GRAY,
val borderWidth : Float = 5F,
val borderRadius : Float = 15F
val borderShape = ShapeDrawable().apply {
shape = RoundRectShape(floatArrayOf(borderRadius, borderRadius, borderRadius, borderRadius, borderRadius, borderRadius, borderRadius, borderRadius), null, null)
paint.color = borderColor
paint.style = Paint.Style.STROKE;
paint.strokeWidth = borderWidth;
}
val backgroundShape = ShapeDrawable().apply {
shape = RoundRectShape(floatArrayOf(borderRadius, borderRadius, borderRadius, borderRadius, borderRadius, borderRadius, borderRadius, borderRadius), null, null)
paint.color = backgroundColor
paint.style = Paint.Style.FILL_AND_STROKE;
}
val composite = LayerDrawable(arrayOf<Drawable>(backgroundShape, borderShape))
view.background = composite