Android-以编程方式(向后兼容)获取listview的突出显示颜色

Android-以编程方式(向后兼容)获取listview的突出显示颜色,android,listview,colors,Android,Listview,Colors,当用户按下listview项时,它会高亮显示,并在放开时返回到其原始颜色。 我想通过编程查询这些是什么颜色 在14之后的Api版本上,我似乎可以使用 (i) Theme.resolveAttribute(int-resid、TypedValue-outValue、boolean-resolveRefs)或 (ii)主题。获取样式属性(int[]属性) 在较旧的Api版本上,由于 android.R.attr.colorActivatedHighlight/colorPressedHighligh

当用户按下listview项时,它会高亮显示,并在放开时返回到其原始颜色。 我想通过编程查询这些是什么颜色

在14之后的Api版本上,我似乎可以使用 (i) Theme.resolveAttribute(int-resid、TypedValue-outValue、boolean-resolveRefs)或 (ii)主题。获取样式属性(int[]属性)

在较旧的Api版本上,由于 android.R.attr.colorActivatedHighlight/colorPressedHighlight 目前还没有

(1) 在API8上是否有一种编程方式来获取这些颜色的方法? (2) 对于主题中的其他一些函数,我有点困惑

例如(iii)主题。获取样式属性(int resid,int[]attrs)

(3) R.attr和R.styleable之间有什么区别?
R.attr应该是R.styleable的替代品(并且基本上有相应的条目),还是它们的用途只是部分重叠。

您应该声明一个选择器,其中包含以下项:

<item android:drawable="@color/selected" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@color/selected" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@color/selected" android:state_focused="true"/>
<item android:drawable="@color/normal" android:state_focused="false" android:state_pressed="false"/>



并将其设置为listRow的背景

谢谢您的回复。。。“将其设置为背景”。。。听起来你好像误解了我。我的问题不是设置任何颜色,而是询问正在使用(已经)的颜色。。“我想通过程序查询这些是什么颜色。”。。。你的声明到底实现了什么?提前感谢哦是的..对不起,但是你为什么需要知道颜色?顺便说一下,stylable是视图的样式,attr用于声明视图可以拥有的任何属性,并且可以通过样式修改(stylable):)对不起,这根本没有回答我的问题
    // ---------------------------------------------                     
     TypedArray Arr2 = getContext().getTheme().obtainStyledAttributes(
               android.R.attr.colorBackground, new int[] {android.R.attr.colorPressedHighlight});
                int colTst2 = arrTst.getColor(0, 0xFF00FF);

    Here it seems not to matter what value I use for resid. What's the point of this parameter?     
<item android:drawable="@color/selected" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@color/selected" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@color/selected" android:state_focused="true"/>
<item android:drawable="@color/normal" android:state_focused="false" android:state_pressed="false"/>