List of usage examples for android.graphics.drawable StateListDrawable addState
public void addState(int[] stateSet, Drawable drawable)
From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java
private static Drawable createOverflowButtonBgBC(int pressedStateColor) { StateListDrawable sld = new StateListDrawable(); sld.addState(new int[] { android.R.attr.state_pressed }, createBgDrawable(pressedStateColor, 0, CORNER_RADIUS, 0, 0)); sld.addState(new int[] {}, new ColorDrawable(Color.TRANSPARENT)); return sld;/* w w w .ja va 2 s. c o m*/ }
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static StateListDrawable createSelector(Drawable normal, Drawable pressed) { StateListDrawable selector = new StateListDrawable(); selector.addState(new int[] { android.R.attr.state_pressed }, pressed.mutate()); selector.addState(new int[0], normal.mutate()); return selector; }
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;/*w w w. j a v a2 s . c o m*/ }
From source file:com.example.util.ImageUtils.java
/** * //from w w w .j av a 2 s . c o m */ private static StateListDrawable getMaskDrawable(Context context) { StateListDrawable stateDrawable = new StateListDrawable(); int statePressed = android.R.attr.state_pressed; final Resources res = context.getResources(); stateDrawable.addState(new int[] { statePressed }, new BitmapDrawable(res, BitmapFactory.decodeResource(res, R.drawable.banner_pressed))); return stateDrawable; }
From source file:org.telegram.ui.ActionBar.Theme.java
public static Drawable createBarSelectorDrawable(int color, boolean masked) { Drawable drawable;// ww w. j a va 2s . co m if (Build.VERSION.SDK_INT >= 21) { Drawable maskDrawable = null; if (masked) { maskPaint.setColor(0xffffffff); maskDrawable = new Drawable() { @Override public void draw(Canvas canvas) { android.graphics.Rect bounds = getBounds(); canvas.drawCircle(bounds.centerX(), bounds.centerY(), AndroidUtilities.dp(18), maskPaint); } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter colorFilter) { } @Override public int getOpacity() { return PixelFormat.UNKNOWN; } }; } ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { color }); return new RippleDrawable(colorStateList, null, maskDrawable); } else { StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color)); stateListDrawable.addState(new int[] { android.R.attr.state_focused }, new ColorDrawable(color)); stateListDrawable.addState(new int[] { android.R.attr.state_selected }, new ColorDrawable(color)); stateListDrawable.addState(new int[] { android.R.attr.state_activated }, new ColorDrawable(color)); stateListDrawable.addState(new int[] {}, new ColorDrawable(0x00000000)); return stateListDrawable; } }
From source file:com.chenl.widgets.flippablestackview.indicator.OrientedPagerSlidingTabLayout.java
private static final StateListDrawable createStateDrawable() { StateListDrawable stateListDrawable = new StateListDrawable(); ColorDrawable normal = new ColorDrawable(Color.TRANSPARENT); ColorDrawable pressed = new ColorDrawable(Color.parseColor("#66000000")); stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);/*from w ww . j a va 2 s .c o m*/ stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressed); stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, normal); stateListDrawable.addState(new int[] {}, normal); return stateListDrawable; }
From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java
public static StateListDrawable addStateDrawable(int nomalColor, int pressColor) { StateListDrawable sd = new StateListDrawable(); sd.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(pressColor)); sd.addState(new int[] { android.R.attr.state_focused }, new ColorDrawable(nomalColor)); sd.addState(new int[] {}, new ColorDrawable(nomalColor)); return sd;//from w w w . ja v a2s .c om }
From source file:com.esri.android.ecologicalmarineunitexplorer.bottomsheet.BottomSheetFragment.java
/** * Build a stateful drawable for a given EMU * @param emuName String representing name * @return StateListDrawable responsive to selected, pressed, and enabled states */// w w w . j a v a 2 s. c o m private static StateListDrawable buildStateList(final int emuName) { final StateListDrawable stateListDrawable = new StateListDrawable(); final GradientDrawable defaultShape = new GradientDrawable(); final int color = Color.parseColor(EmuHelper.getColorForEMUCluster(emuName)); defaultShape.setColor(color); final GradientDrawable selectedPressShape = new GradientDrawable(); selectedPressShape.setColor(color); selectedPressShape.setStroke(5, Color.parseColor("#f4f442")); stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape); stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape); stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape); return stateListDrawable; }
From source file:com.apptentive.android.sdk.util.Util.java
/** * helper method to generate the ImageButton background with specified highlight color. * * @param selected_color the color shown as highlight * @return/*from w w w . java 2s. c o m*/ */ public static StateListDrawable getSelectableImageButtonBackground(int selected_color) { ColorDrawable selectedColor = new ColorDrawable(selected_color); StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_pressed }, selectedColor); states.addState(new int[] { android.R.attr.state_activated }, selectedColor); return states; }
From source file:com.itheima.googlemarket.PagerSlidingTabStrip.java
/** */ public static StateListDrawable createSelector(Drawable pressDrawable, Drawable normalDrawable) { StateListDrawable stateListDrawable = new StateListDrawable(); // // ?//from ww w .ja v a 2 s .com int[] pressState = { android.R.attr.state_pressed, android.R.attr.state_enabled }; // ? int[] normalState = {}; stateListDrawable.addState(pressState, pressDrawable); // ?Drawable stateListDrawable.addState(normalState, normalDrawable);// ?Drawable return stateListDrawable; }