code: public static int getThemeColorFromAttrOrRes(Context ctx, @AttrRes int attr, @ColorRes int res) {
          int color = getThemeColor(ctx, attr);
          if (color == 0) {
              color = ResourcesCompat.getColor(ctx.getResources(), res, ctx.getTheme());
          }
          return color;
      }
docs: helper method to get the color by attr (which is defined in the style) or by resource.
  
  @param ctx
  @param attr
  @param res
  @return