List of usage examples for android.support.v4.widget CompoundButtonCompat setButtonTintList
public static void setButtonTintList(@NonNull CompoundButton button, @Nullable ColorStateList tint)
From source file:com.github.dfa.diaspora_android.ui.theme.ThemeHelper.java
public static void updateCheckBoxColor(CheckBox checkBox) { if (checkBox != null) { int states[][] = { { android.R.attr.state_checked }, {} }; int colors[] = { ThemeHelper.getAccentColor(), getNeutralGreyColor() }; CompoundButtonCompat.setButtonTintList(checkBox, new ColorStateList(states, colors)); }/*from w w w. j ava 2 s . c o m*/ }
From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) { TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.CompoundButton, defStyleAttr, 0);// w w w. j a va 2 s. c o m try { if (a.hasValue(R.styleable.CompoundButton_android_button)) { final int resourceId = a.getResourceId(R.styleable.CompoundButton_android_button, 0); if (resourceId != 0) { mView.setButtonDrawable(mDrawableManager.getDrawable(mView.getContext(), resourceId)); } } if (a.hasValue(R.styleable.CompoundButton_buttonTint)) { CompoundButtonCompat.setButtonTintList(mView, a.getColorStateList(R.styleable.CompoundButton_buttonTint)); } if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) { CompoundButtonCompat.setButtonTintMode(mView, DrawableUtils.parseTintMode(a.getInt(R.styleable.CompoundButton_buttonTintMode, -1), null)); } } finally { a.recycle(); } }
From source file:com.facebook.react.views.checkbox.ReactCheckBoxManager.java
@ReactProp(name = "tintColors") public void setTintColors(ReactCheckBox view, @Nullable ReadableMap colorsMap) { String defaultColorIdOfCheckedState = "colorAccent"; int trueColor = colorsMap == null || !colorsMap.hasKey("true") ? getThemeColor(view.getContext(), defaultColorIdOfCheckedState) : colorsMap.getInt("true"); String defaultColorIdOfUncheckedState = "colorPrimaryDark"; int falseColor = colorsMap == null || !colorsMap.hasKey("false") ? getThemeColor(view.getContext(), defaultColorIdOfUncheckedState) : colorsMap.getInt("false"); ColorStateList csl = new ColorStateList(new int[][] { new int[] { android.R.attr.state_checked }, new int[] { -android.R.attr.state_checked } }, new int[] { trueColor, falseColor, }); CompoundButtonCompat.setButtonTintList(view, csl); }
From source file:com.rubengees.introduction.IntroductionFragment.java
@NonNull private View initDefaultViews(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.introduction_fragment_default_content, container, false);/*from w w w .ja va 2s .com*/ TextView title = (TextView) root.findViewById(R.id.introduction_fragment_default_content_title); ImageView image = (ImageView) root.findViewById(R.id.introduction_fragment_default_content_image); ViewGroup descriptionContainer = (ViewGroup) root .findViewById(R.id.introduction_fragment_default_content_description_container); TextView description; if (slide.getTitle() != null) { title.setText(slide.getTitle()); title.setMaxLines(getLineCountForTitle()); title.setTypeface(IntroductionConfiguration.getInstance().getTitleTypeface()); if (slide.getTitleSize() != null) { title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, slide.getTitleSize()); } } if (slide.getDescription() == null && slide.getOption() != null) { AppCompatCheckBox option = (AppCompatCheckBox) inflater.inflate(R.layout.introduction_fragment_option, descriptionContainer, false); option.setText(slide.getOption().getTitle()); option.setChecked(slide.getOption().isActivated()); option.setMaxLines(getLineCountForDescription()); option.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { slide.getOption().setActivated(isChecked); } }); CompoundButtonCompat.setButtonTintList(option, ContextCompat.getColorStateList(getContext(), android.R.color.white)); descriptionContainer.addView(option); description = option; } else { description = (TextView) inflater.inflate(R.layout.introduction_fragment_description, descriptionContainer, false); if (slide.getDescription() != null) { description.setText(slide.getDescription()); } description.setMaxLines(getLineCountForDescription()); descriptionContainer.addView(description); } description.setTypeface(IntroductionConfiguration.getInstance().getDescriptionTypeface()); if (slide.getDescriptionSize() != null) { description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, slide.getDescriptionSize()); } if (slide.getImageResource() != null) { image.setImageResource(slide.getImageResource()); } IntroductionConfiguration.getInstance().callOnSlideInit(slide.getPosition(), title, image, description); return root; }
From source file:com.owncloud.android.utils.ThemeUtils.java
public static void tintCheckbox(AppCompatCheckBox checkBox, int color) { CompoundButtonCompat .setButtonTintList(checkBox, new ColorStateList( new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked }, }, new int[] { Color.GRAY, color })); }
From source file:com.mobicage.rogerthat.util.ui.UIUtils.java
public static void setColors(int color, View... views) { if (Build.VERSION.SDK_INT >= 27) { return;//from www .j a v a 2 s.c o m } for (View view : views) { if (view instanceof CheckBox) { CheckBox checkbox = (CheckBox) view; CompoundButtonCompat.setButtonTintList(checkbox, ColorStateList.valueOf(color)); } else if (view instanceof FloatingActionButton) { //noinspection RedundantCast ((FloatingActionButton) view).setBackgroundTintList(ColorStateList.valueOf(color)); } else if (view instanceof Button || view instanceof ImageButton) { Drawable background = view.getBackground(); if (background != null) { background.setColorFilter(color, PorterDuff.Mode.SRC_IN); } } else if (view instanceof TextInputLayout) { UIUtils.colorTextInputLayout((TextInputLayout) view, color); // TODO: EditText's who are a child of TextInputLayout their line isn't colored correctly } else if (view instanceof EditText) { EditText editText = (EditText) view; editText.setHighlightColor(color); // When selecting text editText.setHintTextColor(color); // Text for the hint message // Line under the textfield Drawable background = editText.getBackground(); if (background != null) { DrawableCompat.setTint(background, color); editText.setBackground(background); } UIUtils.setCursorColor(editText, color); } else if (view instanceof CheckedTextView) { CheckedTextView ctv = (CheckedTextView) view; Drawable d = ctv.getCheckMarkDrawable(); d.setColorFilter(color, PorterDuff.Mode.SRC_IN); } else if (view instanceof TextView) { ((TextView) view).setLinkTextColor(color); } else if (view instanceof SeekBar) { SeekBar sb = (SeekBar) view; Drawable progress = sb.getProgressDrawable(); if (progress != null) { progress.setColorFilter(color, PorterDuff.Mode.SRC_IN); } Drawable thumb = sb.getThumb(); if (thumb != null) { thumb.setColorFilter(color, PorterDuff.Mode.SRC_IN); } } else if (view instanceof ProgressBar) { ((ProgressBar) view).getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN); } else { L.d("Not coloring view: " + view.toString()); } } }