Example usage for android.content.res ColorStateList ColorStateList

List of usage examples for android.content.res ColorStateList ColorStateList

Introduction

In this page you can find the example usage for android.content.res ColorStateList ColorStateList.

Prototype

public ColorStateList(int[][] states, @ColorInt int[] colors) 

Source Link

Document

Creates a ColorStateList that returns the specified mapping from states to colors.

Usage

From source file:Main.java

/**
 * creates text's colors state list. This has two colors, one for enabled and the other for disabled button state.
 *
 * @param enabledTextColor// w  w w  .  j a v a  2  s  . co m
 * @param disabledTextColor
 * @return
 */
public static ColorStateList getTextStateColor(int enabledTextColor, int disabledTextColor) {
    int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, new int[] {}, };

    int[] colors = new int[] { enabledTextColor, disabledTextColor };
    return new ColorStateList(states, colors);
}

From source file:Main.java

public static ColorStateList colorStateListIcon(Context context) {
    int[][] states = new int[][] { new int[] { android.R.attr.state_enabled },
            new int[] { -android.R.attr.state_enabled }, new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_pressed } };
    int[] colors = new int[] { getTextColorSecondary(context), getPrimaryColor(context),
            getPrimaryColor(context), getPrimaryColor(context) };
    return new ColorStateList(states, colors);
}

From source file:Main.java

public static ColorStateList createColorStateList(int normal, int pressed, int focused, int unable) {
    int[] colors = new int[] { pressed, focused, normal, focused, unable, normal };
    int[][] states = new int[6][];
    states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled };
    states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused };
    states[2] = new int[] { android.R.attr.state_enabled };
    states[3] = new int[] { android.R.attr.state_focused };
    states[4] = new int[] { android.R.attr.state_window_focused };
    states[5] = new int[] {};
    ColorStateList colorList = new ColorStateList(states, colors);
    return colorList;
}

From source file:Main.java

private static ColorStateList createColorStateList(String b, int pressed, int normal) {
    int[] colors = new int[] { pressed, normal };
    int[][] states = new int[2][];
    states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled };
    states[1] = new int[] {};
    return new ColorStateList(states, colors);
}

From source file:Main.java

public static ColorStateList generateBackColorWithTintColor(final int tintColor) {
    int[][] states = new int[][] { { -ENABLE_ATTR, CHECKED_ATTR }, { -ENABLE_ATTR },
            { CHECKED_ATTR, PRESSED_ATTR }, { -CHECKED_ATTR, PRESSED_ATTR }, { CHECKED_ATTR },
            { -CHECKED_ATTR } };/*from  w  ww  . ja v a  2s . c  o m*/

    int[] colors = new int[] { tintColor - 0xE1000000, 0x10000000, tintColor - 0xD0000000, 0x20000000,
            tintColor - 0xD0000000, 0x20000000 };
    return new ColorStateList(states, colors);
}

From source file:Main.java

public static ColorStateList toColorStateList(int normalColor, int pressedColor, int focusedColor,
        int unableColor) {
    int[] colors = new int[] { pressedColor, focusedColor, normalColor, focusedColor, unableColor,
            normalColor };/*from   ww w.j a va2  s .c  om*/
    int[][] states = new int[6][];
    states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled };
    states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused };
    states[2] = new int[] { android.R.attr.state_enabled };
    states[3] = new int[] { android.R.attr.state_focused };
    states[4] = new int[] { android.R.attr.state_window_focused };
    states[5] = new int[] {};
    return new ColorStateList(states, colors);
}

From source file:Main.java

public static ColorStateList generateThumbColorWithTintColor(final int tintColor) {
    int[][] states = new int[][] { { -ENABLE_ATTR, CHECKED_ATTR }, { -ENABLE_ATTR },
            { PRESSED_ATTR, -CHECKED_ATTR }, { PRESSED_ATTR, CHECKED_ATTR }, { CHECKED_ATTR },
            { -CHECKED_ATTR } };//from   w ww.  j a  v  a  2s  . c om

    int[] colors = new int[] { tintColor - 0xAA000000, 0xFFBABABA, tintColor - 0x99000000,
            tintColor - 0x99000000, tintColor | 0xFF000000, 0xFFEEEEEE };
    return new ColorStateList(states, colors);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@NonNull/*  www .  j a  v a2 s .  c  o  m*/
private static ColorStateList getPressedColorSelector(int normalColor, int pressedColor) {
    return new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed },
            new int[] { android.R.attr.state_focused }, new int[] { android.R.attr.state_activated },
            new int[] {} }, new int[] { pressedColor, pressedColor, pressedColor, normalColor });
}

From source file:Main.java

public static ColorStateList createButtonTextColorStateList(int[] colors) {
    int[][] states = { { android.R.attr.state_pressed }, { android.R.attr.state_focused },
            { android.R.attr.state_enabled }, { -android.R.attr.state_enabled } };
    return new ColorStateList(states, colors);
}

From source file:Main.java

public static ColorStateList createColorStateList(int normal, int pressed, int focused, int checked,
        int unable) {
    int[] colors = new int[] { pressed, focused, checked, normal, unable };
    int[][] states = new int[5][];
    states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled };
    states[1] = new int[] { android.R.attr.state_focused, android.R.attr.state_enabled };
    states[2] = new int[] { android.R.attr.state_checked, android.R.attr.state_enabled };
    states[3] = new int[] { android.R.attr.state_enabled };
    states[4] = new int[] {};
    return new ColorStateList(states, colors);
}