Java Code Examples for android.support.v4.content.ContextCompat#getColorStateList()
The following examples show how to use
android.support.v4.content.ContextCompat#getColorStateList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockEditText.java From BlockEditText with Apache License 2.0 | 6 votes |
public void setHint(String hint) { if (hintTextView == null) { hintTextView = new ATextView(getContext()); hintTextView.setPadding(16, 0, 16, 0); setHintTextAppearance(hintTextAppearance); setHintTextSize(hintTextAppearance); linearLayout.addView(hintTextView, 0); hintColorDefault = hintTextView.getHintTextColors(); hintColorFocus = ContextCompat.getColorStateList( getContext(), R.color.colorAccent ); } hintTextView.setVisibility(hint == null ? GONE : VISIBLE); hintTextView.setHint(hint); }
Example 2
Source File: SkinnableTextView.java From SkinSprite with MIT License | 6 votes |
@Override public void applyDayNight() { Context context = getContext(); int key; key = R.styleable.SkinnableView[R.styleable.SkinnableView_android_background]; Integer backgroundResource = mAttrsHelper.getAttributeResource(key); if (backgroundResource != null) { Drawable background = ContextCompat.getDrawable(context, backgroundResource); setBackgroundDrawable(background); } key = R.styleable.SkinnableView[R.styleable.SkinnableView_backgroundTint]; int backgroundTintResource = mAttrsHelper.getAttributeResource(key); if (backgroundTintResource > 0) { ColorStateList backgroundTint = ContextCompat.getColorStateList(context, backgroundTintResource); setSupportBackgroundTintList(backgroundTint); } key = R.styleable.SkinnableTextView[R.styleable.SkinnableTextView_android_textColor]; int textColorResource = mAttrsHelper.getAttributeResource(key); if (textColorResource > 0) { ColorStateList color = ContextCompat.getColorStateList(context, textColorResource); setTextColor(color); } }
Example 3
Source File: SkinnableButton.java From SkinSprite with MIT License | 6 votes |
@Override public void applyDayNight() { Context context = getContext(); int key; key = R.styleable.SkinnableView[R.styleable.SkinnableView_android_background]; int backgroundResource = mAttrsHelper.getAttributeResource(key); if (backgroundResource > 0) { Drawable background = ContextCompat.getDrawable(context, backgroundResource); setBackgroundDrawable(background); } key = R.styleable.SkinnableView[R.styleable.SkinnableView_backgroundTint]; int backgroundTintResource = mAttrsHelper.getAttributeResource(key); if (backgroundTintResource > 0) { ColorStateList backgroundTint = ContextCompat.getColorStateList(context, backgroundTintResource); setSupportBackgroundTintList(backgroundTint); } key = R.styleable.SkinnableTextView[R.styleable.SkinnableButton_android_textColor]; int textColorResource = mAttrsHelper.getAttributeResource(key); if (textColorResource > 0) { ColorStateList color = ContextCompat.getColorStateList(context, textColorResource); setTextColor(color); } }
Example 4
Source File: SkinCompatResources.java From AndroidSkinAnimator with MIT License | 5 votes |
public ColorStateList getColorStateList(int resId) { ColorStateList colorStateList = ContextCompat.getColorStateList(mAppContext, resId); if (isDefaultSkin) { return colorStateList; } String resName = mAppContext.getResources().getResourceEntryName(resId); int targetResId = mResources.getIdentifier(resName, "color", mSkinPkgName); return targetResId == 0 ? colorStateList : mResources.getColorStateList(targetResId); }
Example 5
Source File: StepperLayout.java From android-material-stepper with Apache License 2.0 | 5 votes |
private void initDefaultValues() { mBackButtonColor = mNextButtonColor = mCompleteButtonColor = ContextCompat.getColorStateList(getContext(), R.color.ms_bottomNavigationButtonTextColor); mSelectedColor = ContextCompat.getColor(getContext(), R.color.ms_selectedColor); mUnselectedColor = ContextCompat.getColor(getContext(), R.color.ms_unselectedColor); mErrorColor = ContextCompat.getColor(getContext(), R.color.ms_errorColor); mBackButtonText = getContext().getString(R.string.ms_back); mNextButtonText = getContext().getString(R.string.ms_next); mCompleteButtonText = getContext().getString(R.string.ms_complete); }
Example 6
Source File: DemoCustomView02Adapter.java From RecyclerTabLayout with Apache License 2.0 | 5 votes |
private Drawable loadIconWithTint(Context context, @DrawableRes int resourceId) { Drawable icon = ContextCompat.getDrawable(context, resourceId); ColorStateList colorStateList = ContextCompat .getColorStateList(context,R.color.custom_view02_tint); icon = DrawableCompat.wrap(icon); DrawableCompat.setTintList(icon, colorStateList); return icon; }
Example 7
Source File: AudioPlayer.java From Conversations with GNU General Public License v3.0 | 5 votes |
private boolean init(ViewHolder viewHolder, Message message) { if (viewHolder.darkBackground) { viewHolder.runtime.setTextAppearance(this.messageAdapter.getContext(), R.style.TextAppearance_Conversations_Caption_OnDark); } else { viewHolder.runtime.setTextAppearance(this.messageAdapter.getContext(), R.style.TextAppearance_Conversations_Caption); } viewHolder.progress.setOnSeekBarChangeListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ColorStateList color = ContextCompat.getColorStateList(messageAdapter.getContext(), viewHolder.darkBackground ? R.color.white70 : R.color.green700_desaturated); viewHolder.progress.setThumbTintList(color); viewHolder.progress.setProgressTintList(color); } viewHolder.playPause.setAlpha(viewHolder.darkBackground ? 0.7f : 0.57f); viewHolder.playPause.setOnClickListener(this); if (message == currentlyPlayingMessage) { if (AudioPlayer.player != null && AudioPlayer.player.isPlaying()) { viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_pause_white_36dp : R.drawable.ic_pause_black_36dp); viewHolder.progress.setEnabled(true); } else { viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_play_arrow_white_36dp : R.drawable.ic_play_arrow_black_36dp); viewHolder.progress.setEnabled(false); } return true; } else { viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_play_arrow_white_36dp : R.drawable.ic_play_arrow_black_36dp); viewHolder.runtime.setText(formatTime(message.getFileParams().runtime)); viewHolder.progress.setProgress(0); viewHolder.progress.setEnabled(false); return false; } }
Example 8
Source File: Tints.java From AndroidCommons with Apache License 2.0 | 5 votes |
public static Tint fromColorRes(@ColorRes final int colorId) { return new Tint() { @Override public ColorStateList getColor(Context context) { return ContextCompat.getColorStateList(context, colorId); } }; }
Example 9
Source File: ResUtils.java From Android-utils with Apache License 2.0 | 4 votes |
public static ColorStateList getAttrColorStateList(Context context, int attrRes){ TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(attrRes, typedValue, true); return ContextCompat.getColorStateList(context, typedValue.resourceId); }
Example 10
Source File: ContextUtil.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
public static ColorStateList getColorStateList(@ColorRes int colorRes) { return ContextCompat.getColorStateList(Base.getContext(), colorRes); }
Example 11
Source File: ScrollableNumberPicker.java From ScrollableNumberPicker with MIT License | 4 votes |
private void init(Context context, AttributeSet attrs) { if (isInEditMode()) { return; } LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater.inflate(R.layout.number_picker, this); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ScrollableNumberPicker); Resources res = getResources(); downIcon = typedArray.getResourceId(R.styleable.ScrollableNumberPicker_snp_buttonIconDown, downIcon); upIcon = typedArray.getResourceId(R.styleable.ScrollableNumberPicker_snp_buttonIconUp, upIcon); leftIcon = typedArray.getResourceId(R.styleable.ScrollableNumberPicker_snp_buttonIconLeft, leftIcon); rightIcon = typedArray.getResourceId(R.styleable.ScrollableNumberPicker_snp_buttonIconRight, rightIcon); mMinValue = typedArray.getInt(R.styleable.ScrollableNumberPicker_snp_minValue, res.getInteger(R.integer.default_minValue)); mMaxValue = typedArray.getInt(R.styleable.ScrollableNumberPicker_snp_maxValue, res.getInteger(R.integer.default_maxValue)); mStepSize = typedArray.getInt(R.styleable.ScrollableNumberPicker_snp_stepSize, res.getInteger(R.integer.default_stepSize)); mUpdateIntervalMillis = typedArray.getInt(R.styleable.ScrollableNumberPicker_snp_updateInterval, res.getInteger(R.integer.default_updateInterval)); mOrientation = typedArray.getInt(R.styleable.ScrollableNumberPicker_snp_orientation, LinearLayout.HORIZONTAL); mValue = typedArray.getInt(R.styleable.ScrollableNumberPicker_snp_value, res.getInteger(R.integer.default_value)); mValueTextSize = typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_value_text_size, INVALID_RES); mValueTextColor = typedArray.getColor(R.styleable.ScrollableNumberPicker_snp_value_text_color, 0); mValueTextAppearanceResId = typedArray.getResourceId(R.styleable.ScrollableNumberPicker_snp_value_text_appearance, INVALID_RES); mScrollEnabled = typedArray.getBoolean(R.styleable.ScrollableNumberPicker_snp_scrollEnabled, res.getBoolean(R.bool.default_scrollEnabled)); mButtonColorStateList = ContextCompat.getColorStateList(context, typedArray.getResourceId(R.styleable.ScrollableNumberPicker_snp_buttonBackgroundTintSelector, R.color.btn_tint_selector)); mValueMarginStart = (int) typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_valueMarginStart, res.getDimension(R.dimen.default_value_margin_start)); mValueMarginEnd = (int) typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_valueMarginStart, res.getDimension(R.dimen.default_value_margin_end)); mButtonPaddingLeft = (int) typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_buttonPaddingLeft, res.getDimension(R.dimen.default_button_padding_left)); mButtonPaddingRight = (int) typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_buttonPaddingRight, res.getDimension(R.dimen.default_button_padding_right)); mButtonPaddingTop = (int) typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_buttonPaddingTop, res.getDimension(R.dimen.default_button_padding_top)); mButtonPaddingBottom = (int) typedArray.getDimension(R.styleable.ScrollableNumberPicker_snp_buttonPaddingBottom, res.getDimension(R.dimen.default_button_padding_bottom)); TypedValue outValue = new TypedValue(); res.getValue(R.dimen.default_button_scale_factor, outValue, true); float defaultValue = outValue.getFloat(); mButtonTouchScaleFactor = typedArray.getFloat(R.styleable.ScrollableNumberPicker_snp_buttonTouchScaleFactor, defaultValue); typedArray.recycle(); initViews(); mAutoIncrement = false; mAutoDecrement = false; mUpdateIntervalHandler = new Handler(); }
Example 12
Source File: UiUtils.java From AccountBook with GNU General Public License v3.0 | 4 votes |
public static ColorStateList getColorList(int resId) { return ContextCompat.getColorStateList(UiUtils.getContext(), resId); }
Example 13
Source File: CircularProgressButton.java From ProgressButton with Apache License 2.0 | 4 votes |
private void initAttributes(Context context, AttributeSet attributeSet) { String xmlProvidedSize = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android", "textSize"); String[] parts = xmlProvidedSize.split("\\."); String part1 = parts[0]; textSize = new Integer(part1); if (textSize < 0) { float sourceTextSize = getTextSize(); textSize = (int) (sourceTextSize / getContext().getResources().getDisplayMetrics().density); } TypedArray attr = getTypedArray(context, attributeSet, R.styleable.CircularProgressButton); if (attr == null) { return; } try { mIdleText = attr.getString(R.styleable.CircularProgressButton_pb_textIdle); mCompleteText = attr.getString(R.styleable.CircularProgressButton_pb_textComplete); mCancelText = attr.getString(R.styleable.CircularProgressButton_pb_textCancel); mErrorText = attr.getString(R.styleable.CircularProgressButton_pb_textError); mProgressText = attr.getString(R.styleable.CircularProgressButton_pb_textProgress); mIconComplete = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconComplete, 0); mIconCancel = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconCancel, 0); mIconError = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconError, 0); mCornerRadius = attr.getDimension(R.styleable.CircularProgressButton_pb_cornerRadius, 0); mPaddingProgress = attr.getDimensionPixelSize(R.styleable.CircularProgressButton_pb_paddingProgress, 0); mIndeterminateProgressMode = attr.getBoolean(R.styleable.CircularProgressButton_pb_isIndeterminate, false); int blue = getColor(R.color.pb_blue); int white = getColor(R.color.pb_white); int grey = getColor(R.color.pb_grey); int idleStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorIdle, R.color.pb_idle_state_selector); mIdleColorState = ContextCompat.getColorStateList(context, idleStateSelector); int completeStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorComplete, R.color.pb_complete_state_selector); mCompleteColorState = ContextCompat.getColorStateList(context, completeStateSelector); int cancelStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorCancel, R.color.pb_cancel_state_selector); mCancelColorState = ContextCompat.getColorStateList(context, cancelStateSelector); int errorStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorError, R.color.pb_error_state_selector); mErrorColorState = ContextCompat.getColorStateList(context, errorStateSelector); mColorProgress = attr.getColor(R.styleable.CircularProgressButton_pb_colorProgress, white); mColorIndicator = attr.getColor(R.styleable.CircularProgressButton_pb_colorIndicator, blue); mColorProgressCancelIcon = attr.getColor(R.styleable.CircularProgressButton_pb_colorProgressCancelIcon, mColorIndicator); mColorIndicatorBackground = attr.getColor(R.styleable.CircularProgressButton_pb_colorIndicatorBackground, grey); mIdleStateTextColorAfterClick = attr.getColor(R.styleable.CircularProgressButton_pb_textColorAfterClick, getNormalColor(mIdleColorState)); if (idleStateStrokeColor != -1) { mIdleStateBackgroundColorAfterClick = attr.getColor(R.styleable.CircularProgressButton_pb_backgroundColorAfterClick, getColor(idleStateStrokeColor)); } else { mIdleStateBackgroundColorAfterClick = attr.getColor(R.styleable.CircularProgressButton_pb_backgroundColorAfterClick, getPressedColor(mIdleColorState)); } mColorCancelText = attr.getColor(R.styleable.CircularProgressButton_pb_colorCancelText, getNormalColor(this.getTextColors())); mColorCompleteText = attr.getColor(R.styleable.CircularProgressButton_pb_colorCompleteText, getNormalColor(this.getTextColors())); mColorErrorText = attr.getColor(R.styleable.CircularProgressButton_pb_colorErrorText, getNormalColor(this.getTextColors())); mColorIdleText = getNormalColor(this.getTextColors()); } finally { attr.recycle(); } }
Example 14
Source File: HashtagView.java From hashtag-view with MIT License | 4 votes |
public void setItemTextColorStateListRes(@ColorRes int colorStateRes) { this.itemTextColorStateList = ContextCompat.getColorStateList(getContext(), colorStateRes); }
Example 15
Source File: XOutdatedUtils.java From XFrame with Apache License 2.0 | 2 votes |
/** * getColorStateList过时方法处理 * * @param id 资源id * @return */ public static ColorStateList getColorStateList(@ColorRes int id) { return ContextCompat.getColorStateList(XFrame.getContext(), id); }