public static int fetchContextColor(Context context, int androidAttribute) {
        TypedValue typedValue = new TypedValue();

        TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[]{androidAttribute});
        int color = a.getColor(0, 0);

        a.recycle();

        return color;
    }
public static int fetchContextColor ( Context context , int androidAttribute ) { TypedValue typedValue = new TypedValue ( ) ; TypedArray a = context . obtainStyledAttributes ( typedValue . data , new int [ ] { androidAttribute } ) ; int color = a . getColor ( 0 , 0 ) ; a . recycle ( ) ; return color ; }
This method can be extended to get all android attributes color, string, dimension ...etc

@param context          used to fetch android attribute
@param androidAttribute attribute codes like R.attr.colorAccent
@return in this case color of android attribute