Example usage for android.support.v4.view TintableBackgroundView setSupportBackgroundTintList

List of usage examples for android.support.v4.view TintableBackgroundView setSupportBackgroundTintList

Introduction

In this page you can find the example usage for android.support.v4.view TintableBackgroundView setSupportBackgroundTintList.

Prototype

void setSupportBackgroundTintList(@Nullable ColorStateList tint);

Source Link

Document

Applies a tint to the background drawable.

Usage

From source file:android.support.v7.testutils.AppCompatTintableViewActions.java

/**
 * Sets the passed color state list as the background layer on a {@link View} that
 * implements the {@link TintableBackgroundView} interface.
 *///from w w w  .j a v a2  s.c om
public static ViewAction setBackgroundTintList(final ColorStateList colorStateList) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return allOf(isDisplayed(), TestUtilsMatchers.isTintableBackgroundView());
        }

        @Override
        public String getDescription() {
            return "set background tint list";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();

            TintableBackgroundView tintableBackgroundView = (TintableBackgroundView) view;
            tintableBackgroundView.setSupportBackgroundTintList(colorStateList);

            uiController.loopMainThreadUntilIdle();
        }
    };
}

From source file:org.mariotaku.twidere.util.ThemedLayoutInflaterFactory.java

private static void applyTintableBackgroundViewTint(TintableBackgroundView tintable, int accentColor,
        int noTintColor, int backgroundTintColor, boolean isColorTint) {
    if (tintable instanceof Button) {
    } else if (tintable instanceof EditText) {
        tintable.setSupportBackgroundTintList(ColorStateList.valueOf(backgroundTintColor));
    } else if (isColorTint) {
        final int[][] states = { { android.R.attr.state_selected }, { android.R.attr.state_focused },
                { android.R.attr.state_pressed }, { 0 } };
        final int[] colors = { accentColor, accentColor, accentColor, noTintColor };
        tintable.setSupportBackgroundTintList(new ColorStateList(states, colors));
    } else {/*www .j  a  va 2s  .c o m*/
        tintable.setSupportBackgroundTintList(ColorStateList.valueOf(accentColor));
    }
}