这里以获取 ?attr/actionBarSize和 ?attr/colorAccent的值为例:
//需要获取的值的id:
int[] ints = {android.R.attr.actionBarSize, android.R.attr.colorAccent};
构建typedArray
TypedArray typedArray = context.obtainStyledAttributes(ints);
//第0个值(ints[0]的resId)
float actionBarSize = typedArray.getDimension(0, 0);
//同理,ints[1]的指标
int colorAccent = typedArray.getColor(1, 0);
typedArray.recycle();