给 ImageView 设置 selector 之后,发现没有作用,还好最后解决了。

android:src="@drawable/iview_selector"

其中,iview_selector 是 drawable 下面的 xml 文件。

运行之后,没有任何效果。


最后查看 api 发现,必须设置其为 background 属性:

android:background="@drawable/iview_selector"

设置之后,如果不设置onclick或者ontouch(要返回true)事件,点击也是没有作用的。

Button、ImageView 设置 background 属性才可以让 selector 起作用,而 ImageButton 需要为其设置 src 属性。


关于如何设置selector 可以自行看 sdk 的 api。








更多相关文章

  1. android的android:taskAffinity
  2. ImageView的android:maxHeight,android:minHeight的正确设置
  3. Android(安卓)UI 之自定义标题栏 + 沉浸式状态栏
  4. Android(安卓)UI之TextView实现跑马灯效果
  5. 《Android面试宝典》学习笔记(第二章:布局)
  6. Android(安卓)RelativeLayout 属性
  7. 设置TextView文字居中
  8. Android之screenOrientation和configChanges使用和注意事项
  9. android:属性 layout_alignParentRight android:paddingRight

随机推荐

  1. 我需要介绍MongoDB / NoSQL数据库
  2. MySQL数据库辅助类
  3. Php数据库为GoJs格式化json
  4. MySql新建连接不能运行以及如何导入sql
  5. MySQL定时检查是否宕机并邮件通知
  6. MYSQL使用Select插入,如果选择返回多于1的
  7. cpanel导入大数据库(mysql)的方法
  8. mysql数据库中查看当前使用的数据库是哪
  9. 彻底删除mysql服务(清理注册表)
  10. MYSQL获取更新行的主键ID