当GridView的元素被手指点中时,所设置的背景颜色:
在xml中,GridView元素定义中加入以下内容
android:listSelector="@drawable/grid_selector"
grid_selector.xml中内容为:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/selete_bg" android:state_pressed="true"/>
<item android:state_window_focused="true" android:drawable="@drawable/selete_bg" />
</selector>
设置按下时的背景,未按下时默认,如果要设置未按下时的背景,加入
<itemandroid:state_window_focused="false" android:drawable="@drawable/default_bg"/>