code: public static int getColor(Context context, @AttrRes int attrId) {
          int color = 0;
          TypedArray a = context.obtainStyledAttributes(new int[]{attrId});
          try {
              color = a.getColor(0, 0);
          } catch (UnsupportedOperationException e) {
              error("color", attrId, e);
          }
          a.recycle();
          return color;
      }
docs: Get the color specified by the attribute in the Context's theme.
  
  @since 4.0.0