List of usage examples for android.graphics.drawable StateListDrawable addState
public void addState(int[] stateSet, Drawable drawable)
From source file:org.creativecommons.thelist.activities.RandomActivity.java
public void setButtonTheme(ImageButton button, int normalState, int pressedState, int focusedState) { StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_pressed }, getResources().getDrawable(pressedState)); states.addState(new int[] { android.R.attr.state_focused }, getResources().getDrawable(focusedState)); states.addState(new int[] {}, getResources().getDrawable(normalState)); button.setImageDrawable(states);//from ww w .j a v a 2s . co m }
From source file:com.androguide.honamicontrol.MainActivity.java
private StateListDrawable getColouredTouchFeedback() { StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(Color.parseColor(mAppColor))); states.addState(new int[] { android.R.attr.state_focused }, new ColorDrawable(Color.parseColor(mAppColor))); states.addState(new int[] {}, getResources().getDrawable(android.R.color.transparent)); return states; }
From source file:org.opensilk.common.ui.widget.FloatingActionButton.java
/** * <= api 19//from w ww . j a v a 2s.co m */ protected Drawable createSelectableDrawable() { ShapeDrawable drawableNormal = new ShapeDrawable(new OvalShape()); drawableNormal.getPaint().setColor(mColorNormal); StateListDrawable stateDrawable = new StateListDrawable(); ShapeDrawable drawableHighlight = new ShapeDrawable(new OvalShape()); drawableHighlight.getPaint().setColor(mColorPressed); stateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawableHighlight); stateDrawable.addState(new int[0], null); LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { drawableNormal, stateDrawable }); return layerDrawable; }
From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java
protected void init(Context context) { if (isInitialized) return;//from w w w.jav a 2s. co m 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.filemanager.free.ui.views.FastScroller.java
public void setPressedHandleColor(int i) { handle.setColorFilter(i);/* w ww. j a va 2 s .co m*/ StateListDrawable stateListDrawable = new StateListDrawable(); Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fastscroller_handle_normal); Drawable drawable1 = ContextCompat.getDrawable(getContext(), R.drawable.fastscroller_handle_pressed); stateListDrawable.addState(View.PRESSED_ENABLED_STATE_SET, new InsetDrawable(drawable1, getResources().getDimensionPixelSize(R.dimen.fastscroller_track_padding), 0, 0, 0)); stateListDrawable.addState(View.EMPTY_STATE_SET, new InsetDrawable(drawable, getResources().getDimensionPixelSize(R.dimen.fastscroller_track_padding), 0, 0, 0)); this.handle.setImageDrawable(stateListDrawable); }
From source file:com.justplay1.shoppist.shared.widget.ColorCheckedTextView.java
private void setColor(@ColorInt int color) { StateListDrawable states = new StateListDrawable(); Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_radio_to_on_000); Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_radio_to_on_015); if (isEnabled()) { states.setColorFilter(DrawableUtils.getColorFilter(color)); } else {//from ww w.ja v a2s . co m states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY)); } states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable); states.addState(new int[] { android.R.attr.state_checked }, checked); states.addState(new int[] { android.R.attr.state_enabled }, drawable); states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked); states.addState(new int[] { -android.R.attr.state_enabled }, drawable); setCheckMarkDrawable(states); }
From source file:com.justplay1.shoppist.shared.widget.ColorMultiCheckedBox.java
public void setColor(@ColorInt int color) { StateListDrawable states = new StateListDrawable(); Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_000); Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_015); if (isEnabled()) { states.setColorFilter(DrawableUtils.getColorFilter(color)); } else {//from w ww . j av a 2s. c o m states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY)); } states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable); states.addState(new int[] { android.R.attr.state_checked }, checked); states.addState(new int[] { android.R.attr.state_enabled }, drawable); states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked); states.addState(new int[] { -android.R.attr.state_enabled }, drawable); setButtonDrawable(states); }
From source file:com.justplay1.shoppist.features.settings.widget.ColorCheckBoxPreference.java
@Override protected void onBindView(View view) { super.onBindView(view); CheckBox checkboxView = (CheckBox) view.findViewById(R.id.checkbox); StateListDrawable states = new StateListDrawable(); Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_000); Drawable checked = ContextCompat.getDrawable(getContext(), R.drawable.btn_check_to_on_015); if (isEnabled()) { states.setColorFilter(DrawableUtils.getColorFilter(color)); } else {/* w w w. j a va 2 s .com*/ states.setColorFilter(DrawableUtils.getColorFilter(Color.GRAY)); } states.addState(new int[] { android.R.attr.stateNotNeeded }, drawable); states.addState(new int[] { android.R.attr.state_checked }, checked); states.addState(new int[] { android.R.attr.state_enabled }, drawable); states.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked }, checked); states.addState(new int[] { -android.R.attr.state_enabled }, drawable); checkboxView.setButtonDrawable(states); }
From source file:com.oginotihiro.datepicker.DatePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); int currentView = MONTH_AND_DAY_VIEW; int listPosition = -1; int listPositionOffset = 0; if (savedInstanceState != null) { currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); }// ww w . j a va 2 s . com View view = inflater.inflate(R.layout.oginotihiro_date_picker_dialog, container, false); mDayOfWeekView = (TextView) view.findViewById(R.id.datePickerHeader); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayView.setOnClickListener(this); mSelectedMonthTv = (TextView) view.findViewById(R.id.date_picker_month); mSelectedDayTv = (TextView) view.findViewById(R.id.date_picker_day); mSelectedYearTv = (TextView) view.findViewById(R.id.date_picker_year); mSelectedYearTv.setOnClickListener(this); int[][] states = new int[][] { new int[] { -android.R.attr.state_pressed, -android.R.attr.state_selected }, new int[] { -android.R.attr.state_pressed, android.R.attr.state_selected }, new int[] { android.R.attr.state_pressed } }; int[] colors = new int[] { getResources().getColor(R.color.date_picker_text_normal), mColor, mDarkColor }; ColorStateList csl = new ColorStateList(states, colors); mSelectedMonthTv.setTextColor(csl); mSelectedDayTv.setTextColor(csl); mSelectedYearTv.setTextColor(csl); Activity activity = getActivity(); mYearPickerView = new YearPickerView(activity, this); mDayPickerView = new DayPickerView(activity, this); mAnimator = (ViewAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); AlphaAnimation inAlphaAnimation = new AlphaAnimation(0.0F, 1.0F); inAlphaAnimation.setDuration(300); mAnimator.setInAnimation(inAlphaAnimation); AlphaAnimation outAlphaAnimation = new AlphaAnimation(1.0F, 0.0F); outAlphaAnimation.setDuration(300); mAnimator.setOutAnimation(outAlphaAnimation); mDoneButton = (Button) view.findViewById(R.id.done); StateListDrawable sld = new StateListDrawable(); sld.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(Color.argb(60, Color.red(mColor), Color.green(mColor), Color.blue(mColor)))); mDoneButton.setOnClickListener(this); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { mDoneButton.setBackgroundDrawable(sld); } else { mDoneButton.setBackground(sld); } updateDisplay(); setCurrentView(currentView, true); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } return view; }
From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java
private void setDefaultItemBackground() { TypedValue value = new TypedValue(); int colorControlHighlight = 0; if (mContext.getTheme().resolveAttribute(R.attr.colorControlHighlight, value, true)) { colorControlHighlight = value.data; } else {//from ww w .j a v a 2 s. c o m colorControlHighlight = mDefaultTheme == DefaultTheme.LIGHT ? mContext.getResources().getColor(R.color.snv_ripple_material_light) : mContext.getResources().getColor(R.color.snv_ripple_material_dark); } StateListDrawable drawable = new StateListDrawable(); LayerDrawable checked = new LayerDrawable( new Drawable[] { new ColorDrawable(colorControlHighlight), obtainSelectableItemBackground() }); drawable.addState(CHECKED_STATE_SET, checked); drawable.addState(EMPTY_STATE_SET, obtainSelectableItemBackground()); mItemBackground = drawable; }