Slide 36
Slide 36 text
Parse background attrs
class ColorPickerView ... {
private val materialShapeDrawable = MaterialShapeDrawable(
context, attrs, R.attr.colorPickerStyle, R.style.Widget_App_ColorPickerView
)
init {
inflate(context, R.layout.view_color_picker, this)
...
context.withStyledAttributes(
attrs, R.styleable.ColorPickerView, defStyleAttr, R.style.Widget_App_ColorPickerView
) {
val backgroundTint =
getColorStateListOrThrow(R.styleable.ColorPickerView_backgroundTint)
val elevation =
getDimensionOrThrow(R.styleable.ColorPickerView_android_elevation)
background = materialShapeDrawable
backgroundTintList = backgroundTint
setElevation(elevation)
}
}
}
ColorPickerView.kt