android - DrawableCompat setTint not working on API 19 -


i using drawablecompat tinting drawable below , tinting doesn't seem working on api 19. using support lib version 23.3.0

drawable drawable = textview.getcompounddrawables()[drawableposition]; if (drawable != null) {         if (build.version.sdk_int >= build.version_codes.lollipop) {             drawable.settint(color);         } else {             drawablecompat.settint(drawablecompat.wrap(drawable), color);         }     } 

i had same problem. combined posts in https://stackoverflow.com/a/30928051 , tried apis 17, 19, 21, 22, 23 , n preview 3 supportlib 23.4.0 find solution.

even if mentioned, compat-class use filter pre-lollipop-devices (see https://stackoverflow.com/a/27812472/2170109), it's not working.

now, check api myself , use following code, working on tested apis (for 17 , up).

    // https://stackoverflow.com/a/30928051/2170109     drawable drawable = drawablecompat.wrap(contextcompat.getdrawable(context, r.drawable.vector));     image.setimagedrawable(drawable);      /*      * need use filter | https://stackoverflow.com/a/30880522/2170109      * (even if compat should use pre-api21-devices | https://stackoverflow.com/a/27812472/2170109)      */     int color = contextcompat.getcolor(context, r.color.yourcolor);     if (build.version.sdk_int >= build.version_codes.lollipop) {         drawablecompat.settint(drawable, color);      } else {         drawable.mutate().setcolorfilter(color, porterduff.mode.src_in);     } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -