Example usage for android.graphics.drawable StateListDrawable StateListDrawable

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

Introduction

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

Prototype

public StateListDrawable() 

Source Link

Usage

From source file:Main.java

public static StateListDrawable getDrawable(Drawable normal, Drawable pressed) {
    StateListDrawable sd = new StateListDrawable();

    sd.addState(new int[] { android.R.attr.state_pressed }, pressed);
    sd.addState(new int[] { android.R.attr.state_enabled }, normal);
    sd.addState(new int[] {}, pressed);
    return sd;//from  w  w  w .ja  v a2s .c om
}

From source file:Main.java

public static Drawable getSelectedStateDrawable(Drawable normal, Drawable selected) {
    StateListDrawable drawable = new StateListDrawable();

    drawable.addState(new int[] { -android.R.attr.state_selected }, normal);

    drawable.addState(new int[] { android.R.attr.state_selected }, selected);
    return drawable;
}

From source file:Main.java

public static StateListDrawable getCheckedSelectorDrawable(Drawable normal, Drawable pressed) {
    StateListDrawable bg = new StateListDrawable();
    bg.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, pressed);
    bg.addState(new int[] { android.R.attr.state_enabled }, normal);
    bg.addState(new int[] {}, normal);
    return bg;// w ww  .j a v  a2  s.c  o  m
}

From source file:Main.java

public static StateListDrawable getPressedSelectorDrawable(Drawable normal, Drawable pressed) {
    StateListDrawable bg = new StateListDrawable();
    bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
    bg.addState(new int[] { android.R.attr.state_enabled }, normal);
    bg.addState(new int[] {}, normal);
    return bg;/*from  w w w  .ja va2  s  .  co  m*/
}

From source file:Main.java

public static StateListDrawable createSelector(Drawable normalState, Drawable pressedState) {
    StateListDrawable bg = new StateListDrawable();
    bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressedState);
    bg.addState(new int[] { android.R.attr.state_enabled }, normalState);
    bg.addState(new int[] {}, normalState);
    return bg;//from  ww  w . ja  v  a  2 s .c  o m
}

From source file:Main.java

public static StateListDrawable getSelector(Drawable normalDraw, Drawable pressedDraw) {
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, pressedDraw);
    stateListDrawable.addState(new int[] {}, normalDraw);
    return stateListDrawable;
}

From source file:Main.java

public static StateListDrawable crealeLableSelector(Drawable normalDrawable, Drawable pressedDrawable) {
    StateListDrawable selector = new StateListDrawable();
    selector.addState(new int[] { android.R.attr.state_pressed }, pressedDrawable);
    selector.addState(new int[] {}, normalDrawable);
    return selector;
}

From source file:Main.java

public static StateListDrawable selector(int color) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, getColorDrawable(color));
    drawable.addState(new int[] { android.R.attr.state_focused }, getColorDrawable(color));
    drawable.addState(new int[] { android.R.attr.state_selected }, getColorDrawable(color));
    drawable.addState(new int[] { android.R.attr.state_activated }, getColorDrawable(color));
    return drawable;
}

From source file:Main.java

public static StateListDrawable newSelector(Context context, int idNormal, int idPressed, int idFocused,
        int idUnable) {
    StateListDrawable bg = new StateListDrawable();
    Drawable normal = idNormal == -1 ? null : context.getResources().getDrawable(idNormal);
    Drawable pressed = idPressed == -1 ? null : context.getResources().getDrawable(idPressed);
    Drawable focused = idFocused == -1 ? null : context.getResources().getDrawable(idFocused);
    Drawable unable = idUnable == -1 ? null : context.getResources().getDrawable(idUnable);
    // View.PRESSED_ENABLED_STATE_SET
    bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
    // View.ENABLED_FOCUSED_STATE_SET
    bg.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, focused);
    // View.ENABLED_STATE_SET
    bg.addState(new int[] { android.R.attr.state_enabled }, normal);
    // View.FOCUSED_STATE_SET
    bg.addState(new int[] { android.R.attr.state_focused }, focused);
    // View.WINDOW_FOCUSED_STATE_SET
    bg.addState(new int[] { android.R.attr.state_window_focused }, unable);
    // View.EMPTY_STATE_SET
    bg.addState(new int[] {}, normal);
    return bg;/*from ww w.  jav  a 2 s .  c  om*/
}

From source file:Main.java

public static StateListDrawable toStateListDrawable(Drawable normal, Drawable pressed, Drawable focused,
        Drawable unable) {//from  w w  w  .  j  av a  2 s  . co m
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
    drawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, focused);
    drawable.addState(new int[] { android.R.attr.state_enabled }, normal);
    drawable.addState(new int[] { android.R.attr.state_focused }, focused);
    drawable.addState(new int[] { android.R.attr.state_window_focused }, unable);
    drawable.addState(new int[] {}, normal);
    return drawable;
}