android 动态获取?attr/ 的值 代码获取?attr/

这里以获取 ?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();

猜你喜欢

转载自blog.csdn.net/jingzz1/article/details/105382829
今日推荐