Example usage for android.graphics.drawable StateListDrawable setColorFilter

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

Introduction

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

Prototype

@Override
    public void setColorFilter(ColorFilter colorFilter) 

Source Link

Usage

From source file:com.justplay1.shoppist.shared.widget.ColorCheckedTextView.java

private void setColor(@ColorInt int color) {
    StateListDrawable states = new StateListDrawable();

    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_radio_to_on_000);
    Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_radio_to_on_015);

    if (isEnabled()) {
        states.setColorFilter(DrawableUtils.getColorFilter(color));
    } else {/*  w  w w  . j  ava 2 s. c  om*/
        states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY));
    }

    states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable);
    states.addState(new int[] { android.R.attr.state_checked }, checked);
    states.addState(new int[] { android.R.attr.state_enabled }, drawable);
    states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked);
    states.addState(new int[] { -android.R.attr.state_enabled }, drawable);

    setCheckMarkDrawable(states);
}

From source file:com.justplay1.shoppist.shared.widget.ColorMultiCheckedBox.java

public void setColor(@ColorInt int color) {
    StateListDrawable states = new StateListDrawable();

    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_000);
    Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_015);

    if (isEnabled()) {
        states.setColorFilter(DrawableUtils.getColorFilter(color));
    } else {//w w  w  . j  ava2s .c o  m
        states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY));
    }

    states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable);
    states.addState(new int[] { android.R.attr.state_checked }, checked);
    states.addState(new int[] { android.R.attr.state_enabled }, drawable);
    states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked);
    states.addState(new int[] { -android.R.attr.state_enabled }, drawable);

    setButtonDrawable(states);
}

From source file:com.justplay1.shoppist.features.settings.widget.ColorCheckBoxPreference.java

@Override
protected void onBindView(View view) {
    super.onBindView(view);

    CheckBox checkboxView = (CheckBox) view.findViewById(R.id.checkbox);
    StateListDrawable states = new StateListDrawable();

    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_000);
    Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_015);

    if (isEnabled()) {
        states.setColorFilter(DrawableUtils.getColorFilter(color));
    } else {/*from  w  w w.  java  2s.c  om*/
        states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY));
    }

    states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable);
    states.addState(new int[] { android.R.attr.state_checked }, checked);
    states.addState(new int[] { android.R.attr.state_enabled }, drawable);
    states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked);
    states.addState(new int[] { -android.R.attr.state_enabled }, drawable);

    checkboxView.setButtonDrawable(states);
}