Android中控件的事件——xml设置对应效果state_[pressed,checked,selected,focused]

本篇文章主要是讨论下控件的点击事件

一、在Drawable中添加控件的backgroundColor样式(点击切换颜色)

直接贴测试结果了:【在Drawable中创建xml资源文件,在其中的Selector标签对中添加样式(如下黑色截图)】

ImageButton

ImageView


调用方式:check是Drawable中的资源文件名

 <Button
        android:text="Button"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/button"
        android:background="@drawable/check"
        />
    <!--android:background="@drawable/check"-->
    <!--android:background="@drawable/select"-->
    <!--android:background="@drawable/pressed"-->
    <!--android:background="@drawable/focused"-->
二、在xml中改变textView的点击样式(按下时textColor变色)【不能用于TextView的background,会报错】

1.调用代码和xml代码(Drawable中的资源文件)如下

         

设置监听事件:textView.setOnClickListener(null);【不设置不生效】

效果:按在textView上文字的颜色变为Orange

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值