如何以编程方式获得强调色? [英] How to get accent color programmatically?
本文介绍了如何以编程方式获得强调色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个人如何以编程方式获取以下样式中的强调色?
How would one fetch the accent color set in styles, like below, programmatically?
<item name="android:colorAccent">@color/material_green_500</item>
推荐答案
您可以通过以下方式从当前主题中获取它:
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;
}
这篇关于如何以编程方式获得强调色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文