Android selector(背景选择器)学习记录

来源:互联网 发布:航母访问香港停靠 知乎 编辑:程序博客网 时间:2024/05/16 15:26

selector一般用于点击触碰效果的使用。

其用法就是在drawable中创建一个selector.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_focused="true" android:drawable="@drawable/pc_touch_backgroud"/>    <item android:state_pressed="true" android:drawable="@drawable/pc_touch_backgroud" />    <item android:drawable="@drawable/pc_backgroud"/></selector>

1-2是触碰跟点击时变换的颜色,3是原始状态颜色。

在布局文件中添加

android:background="@drawable/person_selector"android:clickable="true"
这样就可以达到点击的效果了

第一篇博文,有点简陋,见谅!

0 0