How to add button tint programmatically

前端 未结 15 1000
时光取名叫无心
时光取名叫无心 2020-11-30 23:38

In the new AppCompat library, we can tint the button this way:

15条回答
  •  余生分开走
    2020-12-01 00:32

    In addition to Shayne3000's answer you can also use a color resource (not only an int color). Kotlin version:

    var indicatorViewDrawable = itemHolder.indicatorView.background
    indicatorViewDrawable = DrawableCompat.wrap(indicatorViewDrawable)
    val color = ResourcesCompat.getColor(context.resources, R.color.AppGreenColor, null) // get your color from resources
    DrawableCompat.setTint(indicatorViewDrawable, color)
    itemHolder.indicatorView.background = indicatorViewDrawable
    

提交回复
热议问题