android.support.v4.content.ContextCompat#getColorStateList ( )源码实例Demo

下面列出了android.support.v4.content.ContextCompat#getColorStateList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BlockEditText   文件: BlockEditText.java
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);


}
 
源代码2 项目: SkinSprite   文件: SkinnableTextView.java
@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);
    }
}
 
源代码3 项目: SkinSprite   文件: SkinnableButton.java
@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);
    }
}
 
源代码4 项目: AndroidSkinAnimator   文件: SkinCompatResources.java
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);
}
 
源代码5 项目: android-material-stepper   文件: StepperLayout.java
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);
}
 
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;
}
 
源代码7 项目: Conversations   文件: AudioPlayer.java
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;
    }
}
 
源代码8 项目: AndroidCommons   文件: Tints.java
public static Tint fromColorRes(@ColorRes final int colorId) {
    return new Tint() {
        @Override
        public ColorStateList getColor(Context context) {
            return ContextCompat.getColorStateList(context, colorId);
        }
    };
}
 
源代码9 项目: Android-utils   文件: ResUtils.java
public static ColorStateList getAttrColorStateList(Context context, int attrRes){
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attrRes, typedValue, true);
    return ContextCompat.getColorStateList(context, typedValue.resourceId);
}
 
源代码10 项目: PowerFileExplorer   文件: ContextUtil.java
public static ColorStateList getColorStateList(@ColorRes int colorRes) {
    return ContextCompat.getColorStateList(Base.getContext(), colorRes);
}
 
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();
}
 
源代码12 项目: AccountBook   文件: UiUtils.java
public static ColorStateList getColorList(int resId) {
    return ContextCompat.getColorStateList(UiUtils.getContext(), resId);
}
 
源代码13 项目: ProgressButton   文件: CircularProgressButton.java
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();
    }
}
 
源代码14 项目: hashtag-view   文件: HashtagView.java
public void setItemTextColorStateListRes(@ColorRes int colorStateRes) {
    this.itemTextColorStateList = ContextCompat.getColorStateList(getContext(), colorStateRes);
}
 
源代码15 项目: XFrame   文件: XOutdatedUtils.java
/**
 * getColorStateList过时方法处理
 *
 * @param id 资源id
 * @return
 */
public static ColorStateList getColorStateList(@ColorRes int id) {
    return ContextCompat.getColorStateList(XFrame.getContext(), id);
}