如何的Android单击时使视图亮点? [英] Android how to make View highlight when clicked?
问题描述
我在其中的每一行是一个编程膨胀的线性布局,我要对行表现得像ListView的点击时。也就是说,我想该行突出显示完全相同的方式/颜色,默认的ListView一样。我怎么会去这样做?
I have a linear layout in which each row is inflated programatically and I want the rows to behave like the ListView when clicked on. That is, I want the row to highlight in the exact same way/colour that the default ListView does. How would I go about doing this?
推荐答案
好吧,我终于想通了,如何做到这一点...基本上是使用类似的颜色选择,除了代替'颜色'按风格链接的选择完成使用绘制的状态,你可以参考由该用于ListView的默认列表绘制:
Ok I have finally figured out how to do this...basically it is done using a selector like the color selector linked by style except instead of 'color' use a drawable for the states and you can refer to the default list drawable that is used in ListView by this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@android:drawable/list_selector_background" />
</selector>
和使用此XML作为背景我的看法。
and using this xml as the background for my View.
所有公共默认可绘制可以在这里找到:<一href="http://developer.android.com/reference/android/R.drawable.html">http://developer.android.com/reference/android/R.drawable.html
All the public default drawables can be found here: http://developer.android.com/reference/android/R.drawable.html
这篇关于如何的Android单击时使视图亮点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!