如何在运行时获取“ colorControlHighlight”属性的值?

时间:2019-05-29 12:52:09

标签: java android styles android-theme

我看到了这个post,它说明了颜色是在colorControlHighlight中设置的

我尝试验证此属性colorControlHighlight的运行时值

但不确定要检查的代码是什么

我怎么知道要使用哪个索引?

TypedValue typedValue = new TypedValue();
int[] textSizeAttr = new int[] { android.R.attr.colorControlHighlight };
int indexOfAttrTextSize = 0;
TypedArray c = view.getContext().obtainStyledAttributes(typedValue.data, textSizeAttr);
int selectableItemBackground = c.getColor(indexOfAttrTextSize, -1);
c.recycle();

1 个答案:

答案 0 :(得分:0)

您可能要检查this post

还要注意,getColorStateList(int)已经是deprecated since Android Marshmallow。您可能更喜欢使用getColorStateList(int, android.content.res.Resources.Theme)

相关问题