Drawable tinting for api <21

后端 未结 10 1960
情话喂你
情话喂你 2020-11-29 01:56

Is it possible to make drawable tinting work for api < 21?



        
10条回答
  •  抹茶落季
    2020-11-29 02:34

    This will do as you want, and should work on all Android versions of the support library:

    @JvmStatic
    fun getTintedDrawable(inputDrawable: Drawable, @ColorInt color: Int): Drawable {
        val wrapDrawable = DrawableCompat.wrap(inputDrawable.mutate())
        DrawableCompat.setTint(wrapDrawable, color)
        DrawableCompat.setTintMode(wrapDrawable, Mode.SRC_IN)
        return wrapDrawable
    }
    

提交回复
热议问题