class ThemeUtil {

    @ColorInt
    public static int getColor(Context context, int colorAttribute) {
        final TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(colorAttribute, outValue, true);
        if (isColor(outValue)) {
            return outValue.data;
        } else if (outValue.type == TypedValue.TYPE_REFERENCE || outValue.type == TypedValue.TYPE_STRING) {
            try {
                final ColorStateList colors = ContextCompat.getColorStateList(context, outValue.resourceId);
                return colors.getDefaultColor();
            } catch (Resources.NotFoundException ex) {
                Log.d(ThemeUtil.class.getName(), ex.getMessage());
            }
        } else if (outValue.type == TypedValue.TYPE_NULL) {
            return getColorFromStyleable(context, styleableForAttr(colorAttribute));
        }
        // default to cyan in case of errors
        return Color.CYAN;
    }

    private  ThemeUtil();

}