zoukankan      html  css  js  c++  java
  • 点击Button时,显示不同的效果、背景

      很早以前就知道怎么做,但是觉得最好还是写下来.

      在drawable文件夹下,新建一个文件,内容如下:

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

      然后在layout布局里面,给按钮:setBackground。

      解释一下:每个item代表一个约束条件,所以上方文件总共有三个约束条件,  state_pressed、state_focused、分别代表是否按下状态、获得焦点状态,设置了这两个状态,点击按钮时,会改变按钮背景,而在未点击时,背景为:co_1,也就是说,最后一个未标注state的item,表示按钮未点击时的背景.

     

  • 相关阅读:
    第一个SWT程序
    稀疏数组
    算法与数据结构
    《Java核心技术》学习笔记 第1-3章
    算术运算符
    5.11 rw zip file
    5.10 gob序列化
    5.9 piping between writer and reader
    5.7 io.MultiWriter(buf, f)
    5.7 读写 二进制数据
  • 原文地址:https://www.cnblogs.com/lomomiao/p/4832121.html
Copyright © 2011-2022 走看看