How to get accent color programmatically?

前端 未结 7 2394
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 03:32

How would one fetch the accent color set in styles, like below, programmatically?

    @color/material_green_500<         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-05 04:16

    You can fetch it from the current theme in this way:

    private int fetchAccentColor() {
        TypedValue typedValue = new TypedValue();
    
        TypedArray a = mContext.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent });
        int color = a.getColor(0, 0);
    
        a.recycle();
    
        return color;
    }
    

提交回复
热议问题