Example usage for android.graphics.drawable GradientDrawable setColorFilter

List of usage examples for android.graphics.drawable GradientDrawable setColorFilter

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable setColorFilter.

Prototype

public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Specify a color and Porter-Duff mode to be the color filter for this drawable.

Usage

From source file:com.pixby.texo.EditTools.ColorTool.java

private void drawBackground(View v) {
    int color = mSampleColors.get(v.getId());
    LayerDrawable layerDrawable = (LayerDrawable) v.getBackground();
    if (layerDrawable != null) {

        GradientDrawable shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_fill);
        shape.setColorFilter(color, PorterDuff.Mode.MULTIPLY);

        shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_focus);
        int alpha = v.hasFocus() ? 255 : 0;
        shape.setAlpha(alpha);/*from w  ww .  j a v a  2 s  .  c o m*/
    }
}