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;
    }
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 ; }
a helper method to get the color from an attribute

@param ctx
@param attr
@return