本篇文章主要是讨论下控件的点击事件
一、在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