code: public static int getThemeColor(Context ctx, @AttrRes int attr) {
          TypedValue tv = new TypedValue();
          if (ctx.getTheme().resolveAttribute(attr, tv, true)) {
              return tv.resourceId != 0 ? ContextCompat.getColor(ctx, tv.resourceId) : tv.data;
          }
          return 0;
      }
docs: a helper method to get the color from an attribute
  
  @param ctx
  @param attr
  @return