如何取消或定制当点击GridView 的时候出现的那个黄色背景

这篇博客介绍了如何在Android开发中取消或定制GridView被点击时显示的黄色背景。通过设置`android:listSelector`属性为自定义的selector资源,可以实现自定义的选中效果。内容涉及到对gridview的属性配置和drawable资源文件的编辑。
摘要由CSDN通过智能技术生成
  在布局文件xml中的代码:

    <GridView android:id="@+id/xxx"

        android:layout_weight="1.0"
        android:layout_height="0dip"
        android:layout_width="match_parent"
        android:stackFromBottom="true"
        android:visibility="invisible" 

         android:scrollbars="none"
        android:drawSelectorOnTop="false"
         android:listSelector="@drawable/grid_selector"
        android:numColumns="auto_fit"
        android:columnWidth="78dp"
       
    />

    在GridView属性中注意上面红色的那一行.它指定了元素的背景布局文件为dwawable目录下面的grid_selector.xml文件.

    grid_selector.xml文件,有下面的描述:


    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" 

            android:drawable="@drawable/pressed_application_background_static" />
        <item android:state_window_focused="false"  

             android:drawable="@drawable/focused_application_background_static" />
        <item android:state_window_focused="true" 

              android:drawable="@drawable/focused_application_background_static" />
    </selector>

    在此文件中,三个<item>分别指定了在点击图标,聚焦,失焦的情况下使用的元素背景
    通过这样的方法就可以改变其大小,形状以及颜色了,这会使你的GridView制作得更漂亮.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值