类似xml的shape
val drawable = GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
cornerRadius = Utils.dptopx(this@MainActivity,5.0f)
setColor(ContextCompat.getColor(this@MainActivity,R.color.black))
}
只有颜色的drawable
val colorDrawable = ColorDrawable(Color.BLACK)
类似xml的selector
val stateListDrawable = StateListDrawable()
stateListDrawable.addState(intArrayOf(android.R.attr.state_pressed),drawable)
stateListDrawable.addState(intArrayOf(),drawable2)