2020import android .graphics .PorterDuff ;
2121import android .graphics .Rect ;
2222import android .graphics .drawable .Drawable ;
23+ import android .os .Build ;
2324import android .support .annotation .ColorInt ;
2425import android .support .annotation .NonNull ;
2526import android .support .annotation .Nullable ;
@@ -41,13 +42,21 @@ public class TintUtil {
4142 */
4243 public static void tintTextView (@ NonNull TextView textview , ColorStateList tintColor ) {
4344 textview .setTextColor (tintColor );
44- Drawable [] drawables = textview .getCompoundDrawables ();
45-
46- textview .setCompoundDrawables (
47- tintDrawable (drawables [0 ], tintColor ),
48- tintDrawable (drawables [1 ], tintColor ),
49- tintDrawable (drawables [2 ], tintColor ),
50- tintDrawable (drawables [3 ], tintColor ));
45+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
46+ Drawable [] drawables = textview .getCompoundDrawablesRelative ();
47+ textview .setCompoundDrawablesRelative (
48+ tintDrawable (drawables [0 ], tintColor ),
49+ tintDrawable (drawables [1 ], tintColor ),
50+ tintDrawable (drawables [2 ], tintColor ),
51+ tintDrawable (drawables [3 ], tintColor ));
52+ } else {
53+ Drawable [] drawables = textview .getCompoundDrawables ();
54+ textview .setCompoundDrawables (
55+ tintDrawable (drawables [0 ], tintColor ),
56+ tintDrawable (drawables [1 ], tintColor ),
57+ tintDrawable (drawables [2 ], tintColor ),
58+ tintDrawable (drawables [3 ], tintColor ));
59+ }
5160 }
5261
5362 /**
0 commit comments