【问题标题】:how can i get the value of "colorControlHighlight" attribute at runtime?如何在运行时获取“colorControlHighlight”属性的值?
【发布时间】:2019-10-15 02:24:12
【问题描述】:

我看到了这个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();

【问题讨论】:

    标签: java android styles android-theme


    【解决方案1】:

    您可能想查看this post

    另请注意,getColorStateList(int) 已成为 deprecated since Android Marshmallow。您可能更喜欢使用getColorStateList(int, android.content.res.Resources.Theme)

    【讨论】:

    • 我看过你的帖子,但我怎么知道要使用哪个索引?
    • 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();
    猜你喜欢
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2012-05-13
    • 2011-02-09
    • 1970-01-01
    相关资源
    最近更新 更多