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

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

源代码1 项目: android_9.0.0_r45   文件: SuggestionsAdapter.java
private CharSequence formatUrl(Context context, CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = context.getColorStateList(colorValue.resourceId);
    }

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null),
            0, url.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}
 
源代码2 项目: NewsMe   文件: ThemeHelper.java
public static ColorStateList getActionTextColorStateList(Context context, @ColorRes int colorId) {
    final TypedValue value = new TypedValue();
    context.getResources().getValue(colorId, value, true);
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return getActionTextStateList(context, value.data);
    } else {

        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
            //noinspection deprecation
            return context.getResources().getColorStateList(colorId);
        } else {
            return context.getColorStateList(colorId);
        }
    }
}
 
源代码3 项目: AndroidTint   文件: ThemeHelper.java
public static ColorStateList getActionTextColorStateList(Context context, @ColorRes int colorId) {
    final TypedValue value = new TypedValue();
    context.getResources().getValue(colorId, value, true);
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return getActionTextStateList(context, value.data);
    } else {

        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
            //noinspection deprecation
            return context.getResources().getColorStateList(colorId);
        } else {
            return context.getColorStateList(colorId);
        }
    }
}
 
源代码4 项目: proteus   文件: Resource.java
@Nullable
public static ColorStateList getColorStateList(int resId, Context context) {
  try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      return context.getColorStateList(resId);
    } else {
      //noinspection deprecation
      return context.getResources().getColorStateList(resId);
    }

  } catch (Resources.NotFoundException nfe) {
    return null;
  }
}
 
 方法所在类
 同类方法