List of usage examples for android.graphics.drawable StateListDrawable StateListDrawable
public StateListDrawable()
From source file:de.dala.simplenews.utilities.UIUtils.java
public static StateListDrawable getStateListDrawableByColorDrawable(Drawable colorDrawable) { StateListDrawable stateList = new StateListDrawable(); stateList.addState(new int[] { android.R.attr.state_pressed }, colorDrawable); stateList.addState(new int[] { android.R.attr.state_focused }, colorDrawable); stateList.addState(new int[] { android.R.attr.state_checked }, colorDrawable); stateList.addState(new int[] { android.R.attr.state_selected }, colorDrawable); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { stateList.addState(new int[] { android.R.attr.state_activated }, colorDrawable); }//from w ww.j a va 2 s .co m stateList.addState(new int[] {}, new ColorDrawable(Color.WHITE)); return stateList; }
From source file:me.trashout.ui.SelectableImageButton.java
/** * Change background selected color//w w w.j av a2 s .co m * @param color */ public void setBackgroundSelectedColor(int color) { LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(getContext(), R.drawable.background_trash_circle_button_selected); GradientDrawable shape = (GradientDrawable) layerDrawable .findDrawableByLayerId(R.id.selected_background_shape).mutate(); shape.setColor(color); StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_pressed }, shape); states.addState(new int[] { android.R.attr.state_selected }, shape); states.addState(new int[] {}, ContextCompat.getDrawable(getContext(), R.drawable.background_trash_circle_button)); setBackground(states); invalidate(); }
From source file:com.codetroopers.betterpickers.calendardatepicker.YearPickerView.java
/** * @param context/*from w w w.j a v a2 s.co m*/ */ public YearPickerView(Context context, CalendarDatePickerController controller) { super(context); mController = controller; mController.registerOnDateChangedListener(this); ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); setLayoutParams(frame); Resources res = context.getResources(); mViewSize = res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height); mChildSize = res.getDimensionPixelOffset(R.dimen.year_label_height); setVerticalFadingEdgeEnabled(true); setFadingEdgeLength(mChildSize / 3); init(context); setOnItemClickListener(this); setSelector(new StateListDrawable()); setDividerHeight(0); onDateChanged(); mBackgroundColor = R.color.circle_background; mCircleColor = R.color.bpBlue; mTextColor = R.color.ampm_text_color; }
From source file:com.aqtc.bmobnews.util.ResourcesUtils.java
/** * ColorStateList/*w ww. j a v a2 s . c o m*/ * create a StateListDrawable instance * * @param context context * @param normalRes normalRes * @param pressedRes pressedRes * @param focusedRes focusedRes * @param unableRes unableRes * @return StateListDrawable */ public static StateListDrawable createStateListDrawable(Context context, @DrawableRes int normalRes, @DrawableRes int pressedRes, @DrawableRes int focusedRes, @DrawableRes int unableRes) { StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, getDrawable(context, pressedRes)); stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, getDrawable(context, focusedRes)); stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, getDrawable(context, normalRes)); stateListDrawable.addState(new int[] { android.R.attr.state_focused }, getDrawable(context, focusedRes)); stateListDrawable.addState(new int[] { android.R.attr.state_window_focused }, getDrawable(context, unableRes)); stateListDrawable.addState(new int[] {}, getDrawable(context, normalRes)); return stateListDrawable; }
From source file:com.auth0.android.lock.views.ActionButton.java
private Drawable generateStateBackground(Theme lockTheme) { int normalColor = lockTheme.getPrimaryColor(getContext()); int pressedColor = lockTheme.getDarkPrimaryColor(getContext()); int disabledColor = ContextCompat.getColor(getContext(), R.color.com_auth0_lock_submit_disabled); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { return new RippleDrawable(ColorStateList.valueOf(pressedColor), new ColorDrawable(normalColor), null); } else {//from w w w .j a va 2 s . c om StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }, new ColorDrawable(pressedColor)); states.addState(new int[] { android.R.attr.state_enabled }, new ColorDrawable(normalColor)); states.addState(new int[] {}, new ColorDrawable(disabledColor)); return states; } }
From source file:com.vuze.android.remote.spanbubbles.SpanTags.java
private void createDrawTagables() { if (tagDrawables != null) { return;// w ww . j a v a 2 s . com } if (context == null) { return; } Drawable drawableTag = ContextCompat.getDrawable(context, R.drawable.tag_q); Drawable drawableTagIdea = ContextCompat.getDrawable(context, R.drawable.tag_idea); Drawable drawableTagPending = ContextCompat.getDrawable(context, R.drawable.tag_pending); Drawable drawableTagSelected = ContextCompat.getDrawable(context, R.drawable.tag_check); tagDrawables = new StateListDrawable(); tagDrawables.addState(new int[] { android.R.attr.state_middle }, drawableTagPending); tagDrawables.addState(new int[] { android.R.attr.state_middle, android.R.attr.state_checked }, drawableTagPending); tagDrawables.addState(new int[] { android.R.attr.state_checked }, drawableTagSelected); tagDrawables.addState(new int[] { android.R.attr.state_single }, drawableTagIdea); tagDrawables.addState(StateSet.WILD_CARD, drawableTag); }
From source file:Main.java
public static Drawable makeRecoloredDrawable(Context context, BitmapDrawable drawable, int color, boolean withStates) { Bitmap recoloredBitmap = recolorBitmap(drawable, color); BitmapDrawable recoloredDrawable = new BitmapDrawable(context.getResources(), recoloredBitmap); if (!withStates) { return recoloredDrawable; }// ww w. jav a 2s.c om StateListDrawable stateDrawable = new StateListDrawable(); stateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawable); stateDrawable.addState(new int[] { android.R.attr.state_focused }, drawable); stateDrawable.addState(new int[] {}, recoloredDrawable); return stateDrawable; }
From source file:com.itheima.googlemarket.PagerSlidingTabStrip.java
/** */ public static StateListDrawable createSelector(Drawable pressDrawable, Drawable normalDrawable) { StateListDrawable stateListDrawable = new StateListDrawable(); // // ?/* ww w . j a va 2 s. c om*/ 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; }
From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java
protected void init(Context context) { if (isInitialized) return;// w ww .j a v a 2 s .c om isInitialized = true; setOrientation(HORIZONTAL); setClipChildren(false); setWillNotDraw(false); bubble = new TextView(context); bubble.setTextColor(Color.WHITE); bubble.setTextSize(48); GradientDrawable bubbleDrawable = new GradientDrawable(); bubbleDrawable.setColor(0xFFce891e); bubbleDrawable.setSize(getCustomSize(88), getCustomSize(88)); bubbleDrawable.setCornerRadii(new float[] { getCustomSize(44), getCustomSize(44), getCustomSize(44), getCustomSize(44), 0, 0, getCustomSize(44), getCustomSize(44) }); bubble.setBackgroundDrawable(bubbleDrawable); //bubble.setBackgroundResource(R.drawable.recycler_view_fast_scroller__bubble); bubble.setGravity(Gravity.CENTER); LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.RIGHT | Gravity.END; addView(bubble, params); if (bubble != null) bubble.setVisibility(INVISIBLE); handle = new ImageView(context); //handle.setBackgroundResource(R.drawable.recycler_view_fast_scroller__handle); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setSize(getCustomSize(4), getCustomSize(35)); drawable.setColor(0xFFce891e); drawable.setCornerRadius(getCustomSize(5)); GradientDrawable drawable2 = new GradientDrawable(); drawable2.setShape(GradientDrawable.RECTANGLE); drawable2.setSize(getCustomSize(4), getCustomSize(35)); drawable2.setColor(0xFFf3a124); drawable2.setCornerRadius(getCustomSize(5)); StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_selected }, drawable); states.addState(new int[] {}, drawable2); handle.setBackgroundDrawable(states); LayoutParams params2 = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); int dimension = getCustomSize(3); int doubleDimension = dimension * 2; params2.leftMargin = doubleDimension; params2.rightMargin = doubleDimension; handle.setPadding(dimension, 0, dimension, 0); handle.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { v.setBackgroundColor(Color.parseColor("#00891e")); } else { v.setBackgroundColor(Color.parseColor("#44891e")); } } }); addView(handle, params2); }
From source file:com.landenlabs.all_UiDemo.frag.RadioBtnFrag.java
private void addTabBar(RadioGroup tabHolder, float weight, int padding) { final int maxTabs = 4; // tabHolder.removeAllViews(); int[][] states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} }; ColorStateList colorStateList = new ColorStateList(states, new int[] { 0xff00ff00, 0x80ff0000 }); RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, weight); /*/* w w w .j a v a 2s.co m*/ ViewOutlineProvider outlineBoundary; if (Build.VERSION.SDK_INT >= 21) { outlineBoundary = new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setRect(0, 0, 200, 60); // view.getMeasuredWidth(), view.getMeasuredHeight()); } }; } */ String[] pageNames = new String[] { "Home", "Map", "Hourly", "Daily" }; int tabCnt = 0; for (String pageName : pageNames) { RadioButton button = new RadioButton(tabHolder.getContext()); String resName = "tab_" + pageName.toLowerCase(); int resID = getResources().getIdentifier(resName, "drawable", this.getContext().getPackageName()); Drawable tabBtnIcon = getResources().getDrawable(resID); if (tabBtnIcon != null) { if (tabBtnIcon != null && Build.VERSION.SDK_INT >= 21) { tabBtnIcon.setTintMode(PorterDuff.Mode.MULTIPLY); tabBtnIcon.setTintList(colorStateList); } else { tabBtnIcon = DrawableCompat.wrap(tabBtnIcon); DrawableCompat.setTintList(tabBtnIcon.mutate(), colorStateList); DrawableCompat.setTintMode(tabBtnIcon.mutate(), PorterDuff.Mode.MULTIPLY); } // tabBtnIcon = tabHolder.getResources().getDrawable(android.R.drawable.btn_radio); if (Build.VERSION.SDK_INT >= 21) { // Hide standard radio button but leave ripple effect button.setButtonDrawable(null); } else { // Hide standard radio button button.setButtonDrawable(new StateListDrawable()); } button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); /* // button.setBackgroundResource(R.drawable.ripple_boarderless); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); // button.setCompoundDrawablesRelativeWithIntrinsicBounds(null, tabBtnIcon, null, null); // tabBtnIcon.setBounds(0, 0, 50, 100); // img.getMinimumWidth(), img.getMinimumHeight()); // button.setCompoundDrawables(null, tabBtnIcon, null, null); } else { button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null); } */ button.setBackgroundResource(R.drawable.ripple_boarderless); button.setPadding(padding, padding, padding, padding); button.setGravity(Gravity.CENTER); button.setTextColor(colorStateList); button.setText(pageName); tabHolder.addView(button, lp); if (++tabCnt == maxTabs) break; } } }