Java Code Examples for android.content.Context#getColorStateList()

The following examples show how to use android.content.Context#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: SuggestionsAdapter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: ThemeHelper.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: ThemeHelper.java    From AndroidTint with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 4
Source File: Resource.java    From proteus with Apache License 2.0 5 votes vote down vote up
@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;
  }
}