The following kotlin code is used to display a square icon in an Android app. But I would also like to set rounded corners to it; and this is where things go wrong. Any tip would be welcome as what to do to get the rounded corners working.
val apIcnID = resources.getIdentifier("appIcon","id",packageName)
val apIcnCompo = findViewById<ImageView>(apIcnID)
val borderSz = 9F; val cornerRad = 16F
val shape = ShapeDrawable(
RoundRectShape(
floatArrayOf(cornerRad, cornerRad, cornerRad, cornerRad,
cornerRad, cornerRad, cornerRad, cornerRad),
RectF(borderSz, borderSz, borderSz, borderSz),
floatArrayOf(cornerRad, cornerRad, cornerRad, cornerRad,
cornerRad, cornerRad, cornerRad, cornerRad)
)
)
//apIcnCompo.clipToOutline = true // Uncommenting this line hides the whole image.
apIcnCompo.background = shape
apIcnCompo.setImageResource(R.drawable.ic_launcher_myapp)
// I see the square-icon image, but with no single rounded corner ...
Replace cornerRadius with your desired corner radius.
OR