Android中Selector的使用

来源:互联网 发布:macbook 下载软件网站 编辑:程序博客网 时间:2024/05/21 12:51

Android中Selector的使用

学习了那么久,一直没有好好总结过selector的用法,现在就来总结一下。首先要创建一个selector,可以在

<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/p2_normal" android:state_pressed="false"/>    <item android:drawable="@drawable/p2_pressed" android:state_pressed="true"/></selector>

下面是我在layout文件中进行的一个配置

<ImageView       android:layout_width="wrap_content"       android:layout_height="wrap_content"       android:clickable="true"       android:src="@drawable/p2"/>    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:focusable="true"        android:background="@drawable/p2"  />

可以发现,直接进行一个引用就可以了,非常的方便。
在这里,还有一个非常方便的插件,就是通过SelectorChapek工具使用。具体可以参见SelectorChapek工具
这篇博客。第一次写博客,还有很多不懂的地方,全当是一种尝试了。

0 0