Answers for "how to set background to general view in android"

0

how to set background to general view in android

check if the view is Viewgroup or not
fun View.customBg(backgroundColor: Int, borderColor: Int) {

    val shape = GradientDrawable()
    shape.shape = GradientDrawable.RECTANGLE
    shape.cornerRadii = floatArrayOf(8f, 8f, 8f, 8f, 0f, 0f, 0f, 0f)
    shape.setColor(backgroundColor)
    shape.setStroke(3, borderColor)


    if (this is ViewGroup) {
        this.background = shape
    }

}
Posted by: Guest on January-27-2021

Code answers related to "how to set background to general view in android"

Browse Popular Code Answers by Language