code: public static int getColorAttr(Context ctx, @AttrRes int colorAttrId){
          int[] attrs = new int[] { colorAttrId /* index 0 */};
          TypedArray ta = ctx.obtainStyledAttributes(attrs);
          int colorFromTheme = ta.getColor(0, 0);
          ta.recycle();
          return colorFromTheme;
      }
docs: Get the color value for give attribute
  @param ctx
  @param colorAttrId
  @return