update View Tint - Android User Interface

Android examples for User Interface:View

Description

update View Tint

Demo Code


import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.View;

public class Main{
    public static void updateTint(View view, @ColorInt int color) {
        Drawable wrappedDrawable = DrawableCompat
                .wrap(view.getBackground());
        DrawableCompat.setTint(wrappedDrawable.mutate(), color);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(wrappedDrawable);
        } else {//from   w  w  w . j a  va 2s .  c o  m
            view.setBackgroundDrawable(wrappedDrawable);
        }
    }
}

Related Tutorials