android.content.res.Resources#getColorStateList()源码实例Demo

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

源代码1 项目: Android_Skin_2.0   文件: EnvTextViewChanger.java
private void scheduleTextColor(TV view, TVC call) {
	Resources res = view.getResources();
	if (mTextColorHighlightEnvRes != null) {
		int textColorHighlight = res.getColor(mTextColorHighlightEnvRes.getResid());
		call.scheduleHighlightColor(textColorHighlight);
	}
	if (mTextColorEnvRes != null) {
		ColorStateList textColor = res.getColorStateList(mTextColorEnvRes.getResid());
		call.scheduleTextColor(textColor);
	}
	if (mTextColorHintEnvRes != null) {
		ColorStateList textColorHint = res.getColorStateList(mTextColorHintEnvRes.getResid());
		call.scheduleHintTextColor(textColorHint);
	}
	if (mTextColorLinkEnvRes != null) {
		ColorStateList textColorLink = res.getColorStateList(mTextColorLinkEnvRes.getResid());
		call.scheduleLinkTextColor(textColorLink);
	}
}
 
源代码2 项目: letv   文件: ResourcesCompat.java
@Nullable
public static ColorStateList getColorStateList(@NonNull Resources res, @ColorRes int id, @Nullable Theme theme) throws NotFoundException {
    if (VERSION.SDK_INT >= 23) {
        return ResourcesCompatApi23.getColorStateList(res, id, theme);
    }
    return res.getColorStateList(id);
}
 
源代码3 项目: AndroidStudyDemo   文件: ColorStateListActivity.java
@TargetApi(23)
private void testGetColorStateList() {
    ColorStateList csl = getColorStateList(R.color.text_selector1);
    if (csl != null) {
        mTestBtn.setTextColor(csl);
    }

    Resources resources = getResources();
    ColorStateList csl2 = resources.getColorStateList(R.color.text_selector2);
    if (csl2 != null) {
        mTestBtn2.setTextColor(csl2);
    }

}
 
源代码4 项目: NightModel   文件: AttrTypeTextColor.java
@Override
public void apply(View view, String resName) {
    if (TextUtils.isEmpty(resName)) return;
    Resources mResources = view.getResources();
    int resId = mResources.getIdentifier(resName, DEFTYPE_COLOR, view.getContext().getPackageName());
    if (0 != resId) {
        ColorStateList colorList = mResources.getColorStateList(resId);
        if (colorList == null) return;

        ((TextView) view).setTextColor(colorList);
    }
}
 
private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);

    text.removeSpan(obj);

    if (where != len) {
        Font f = (Font) obj;

        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = res.getColorStateList(colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors,
                                    null), where, len,
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000),
                            where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }

        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
 
源代码6 项目: 365browser   文件: ApiCompatibilityUtils.java
/**
 * @see android.content.res.Resources#getColorStateList(int id).
 */
@SuppressWarnings("deprecation")
public static ColorStateList getColorStateList(Resources res, int id) throws NotFoundException {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return res.getColorStateList(id, null);
    } else {
        return res.getColorStateList(id);
    }
}
 
源代码7 项目: Overchan-Android   文件: CompatibilityUtils.java
@SuppressWarnings("deprecation")
public static ColorStateList getColorStateList(Resources resources, int id) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return resources.getColorStateList(id);
    } else {
        return CompatibilityImpl.getColorStateList(resources, id);
    }
}
 
源代码8 项目: NoHttp   文件: ResCompat.java
public static ColorStateList getColorStateList(int colorStateId, Theme theme) {
    Resources resources = NoHttp.getContext().getResources();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        return resources.getColorStateList(colorStateId, theme);
    else
        return resources.getColorStateList(colorStateId);
}
 
源代码9 项目: YiBo   文件: Theme.java
@Override
public ColorStateList getColorStateList(String resName) {
	ColorStateList colorStateList = null;
	
	try {
		Resources res = context.getResources();
		int resId = res.getIdentifier(resName, "color", currentPackageName);
		colorStateList = res.getColorStateList(resId);
	} catch (NotFoundException e) {
		if (Logger.isDebug()) Log.e(TAG, e.getMessage(), e);
	}
	
	return colorStateList;
}
 
源代码10 项目: Overchan-Android   文件: CompatibilityImpl.java
@TargetApi(Build.VERSION_CODES.M)
public static ColorStateList getColorStateList(Resources resources, int id) {
    return resources.getColorStateList(id, null);
}
 
源代码11 项目: Mover   文件: FloatingActionButton.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public FloatingActionButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);
    setClickable(true);

    if(Build.VERSION.SDK_INT > 14 && Build.VERSION.SDK_INT < 16){
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }

    Resources r = context.getResources();

    mInnerCircleOffset = r.getDimensionPixelSize(R.dimen.fab_inner_circle_offset);
    mActionSize = r.getDimensionPixelSize(R.dimen.fab_action_icon_size);

    mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setStyle(Paint.Style.FILL);

    // Resolving attribute styles
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton);

    mCirclePaint.setColor(array.getColor(R.styleable.FloatingActionButton_actionColor, Color.WHITE));
    mActionIcon = array.getDrawable(R.styleable.FloatingActionButton_actionIcon);

    if(mActionIcon != null){
        mActionIcon.setBounds(0, 0, mActionSize, mActionSize);
    }

    array.recycle();

    mCircle = new Circle();
    mCirclePath = new Path();

    ViewUtils.setBackground(this, r.getDrawable(R.drawable.floatingactionbutton_shadow_layer));

    mRippleDrawable = new RippleDrawable(r.getColorStateList(R.color.overlay_color), null);
    mRippleDrawable.setVisible(true, false);
    mRippleDrawable.setCallback(this);
    mRippleDrawable.setState(getDrawableState());

    setOnTouchListener(new TouchTracker());
}
 
源代码12 项目: Genius-Android   文件: EditText.java
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    if (attrs == null)
        return;

    // Get the super padding top
    mTruePaddingTop = super.getPaddingTop();

    final Context context = getContext();
    final Resources resources = getResources();

    TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.EditText, defStyleAttr, defStyleRes);

    String fontFile = a.getString(R.styleable.EditText_gFont);
    int lineSize = a.getDimensionPixelSize(R.styleable.EditText_gLineSize, resources.getDimensionPixelSize(R.dimen.g_editText_lineSize));
    ColorStateList lineColor = a.getColorStateList(R.styleable.EditText_gLineColor);

    // Set HintProperty
    int titleModel = a.getInt(R.styleable.EditText_gHintTitle, 1);
    int titleTextSize = a.getDimensionPixelSize(R.styleable.EditText_gHintTitleTextSize, resources.getDimensionPixelSize(R.dimen.g_editText_hintTitleTextSize));
    int titlePaddingTop = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingTop, 0);
    int titlePaddingBottom = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingBottom, 0);
    int titlePaddingLeft = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingLeft, 0);
    int titlePaddingRight = a.getDimensionPixelSize(R.styleable.EditText_gHintTitlePaddingRight, 0);

    a.recycle();

    // Init color
    if (lineColor == null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            lineColor = resources.getColorStateList(R.color.g_default_edit_view_line, null);
        } else {
            //noinspection deprecation
            lineColor = resources.getColorStateList(R.color.g_default_edit_view_line);
        }
    }

    if (!Ui.isHaveAttribute(attrs, "textColorHint") || getHintTextColors() == null) {
        ColorStateList hintColor;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            hintColor = resources.getColorStateList(R.color.g_default_edit_view_hint, null);
        } else {
            //noinspection deprecation
            hintColor = resources.getColorStateList(R.color.g_default_edit_view_hint);
        }
        setHintTextColor(hintColor);
    }

    // Set same values
    setLineSize(lineSize);
    setLineColor(lineColor);

    setHintTitleTextSize(titleTextSize);
    setHintTitleModel(titleModel);

    // check for IDE preview render
    if (!this.isInEditMode()) {
        // Set Font
        if (fontFile != null && fontFile.length() > 0) {
            Typeface typeface = Ui.getFont(context, fontFile);
            if (typeface != null) setTypeface(typeface);
        }
    }

    // Init background and title
    if (!Ui.isHaveAttribute(attrs, "background")) {
        initBackground();
    }

    initHintTitleText();

    // SetHintPadding
    setHintTitlePadding(titlePaddingLeft, titlePaddingTop, titlePaddingRight, titlePaddingBottom);
}
 
源代码13 项目: Genius-Android   文件: CheckBox.java
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final Context context = getContext();
    final Resources resource = getResources();
    final float density = resource.getDisplayMetrics().density;
    final int baseSize = (int) (density * 2);

    if (attrs == null) {
        mMarkDrawable = new CircleCheckDrawable(resource.getColorStateList(R.color.g_default_check_box));
        setButtonDrawable(mMarkDrawable);
        return;
    }

    // Load attributes
    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.CheckBox, defStyleAttr, defStyleRes);

    int borderSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gBorderSize, baseSize);
    int intervalSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gIntervalSize, baseSize);
    int markSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gMarkSize, -1);
    ColorStateList color = a.getColorStateList(R.styleable.CheckBox_gMarkColor);
    String fontFile = a.getString(R.styleable.CheckBox_gFont);

    a.recycle();

    if (color == null)
        color = resource.getColorStateList(R.color.g_default_check_box);

    boolean isCustom = true;

    if (markSize < 0) {
        markSize = (int) (density * 22);
        isCustom = false;
    }

    mMarkDrawable = new CircleCheckDrawable(color);
    mMarkDrawable.setBorderSize(borderSize);
    mMarkDrawable.setIntervalSize(intervalSize);
    mMarkDrawable.setMarkSize(markSize, isCustom);
    mMarkDrawable.inEditMode(isInEditMode());
    setButtonDrawable(mMarkDrawable);

    // Check for IDE preview render
    if (!this.isInEditMode()) {
        // Font
        if (fontFile != null && fontFile.length() > 0) {
            Typeface typeface = Ui.getFont(getContext(), fontFile);
            if (typeface != null) setTypeface(typeface);
        }
    }
}
 
源代码14 项目: Genius-Android   文件: UiCompat.java
/**
 * Returns a themed color state list associated with a particular resource
 * ID. The resource may contain either a single raw color value or a
 * complex {@link ColorStateList} holding multiple possible colors.
 *
 * @param resources Resources
 * @param id        The desired resource identifier of a {@link ColorStateList},
 *                  as generated by the aapt tool. This integer encodes the
 *                  package, type, and resource entry. The value 0 is an invalid
 *                  identifier.
 * @return A themed ColorStateList object containing either a single solid
 * color or multiple colors that can be selected based on a state.
 */
public static ColorStateList getColorStateList(Resources resources, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return resources.getColorStateList(id, null);
    } else {
        return resources.getColorStateList(id);
    }
}