取消GridView/ListView item被点击时的效果

方法一,在控件被初始化的时候设置

1
2
gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
listView.setSelector(new ColorDrawable(Color.TRANSPARENT));

方法二,在布局文件中设置listSelector属性

 

1
2
3
4
5
6
7
8
9
10
11
12
13
<GridView
        android:listSelector="@android:color/transparent"
        android:numColumns="auto_fit"
        android:columnWidth="50dp"
        android:stretchMode="spacingWidth"
        android:layout_weight="1.0"
        android:layout_height="0dip"
        android:layout_width="match_parent"/>
 
<ListView
        android:listSelector="@android:color/transparent"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

当然也可以定制化自己想要的效果。 

推荐使用方法二,解耦逻辑代码与布局文件。

posted on 2015-04-28 14:42  %幻#影%  阅读(575)  评论(0)    收藏  举报

导航