android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现

首先看到selector的属性:
android:state_focused
android:state_pressed
android:state_selected
android:state_enabled

它们之间的执行是 有执行顺序的写xml的时候特别要分析好执行顺序,否则达不到要实现的效果:

现在实现效果如下:


当点击停止按钮时,




有点击效果,和选中效果。
具体代码如下:
暂停:


<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/icon_pause_active" android:state_pressed="true"/>

    <item android:drawable="@drawable/icon_pause_active" android:state_selected="true"/>

    <item android:drawable="@drawable/icon_pause_inactive" android:state_enabled="true"/>

</selector>


停止;
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true" android:drawable="@drawable/icon_stop_active"/>

<item android:state_selected="true" android:drawable="@drawable/icon_stop_active"/>

<item android:state_enabled="true" android:drawable="@drawable/icon_stop_inactive"/>

播放:

</selector>


<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

  <item android:state_pressed="true" android:drawable="@drawable/icon_play_active"/>

<item android:state_selected="true" android:drawable="@drawable/icon_play_active"/>

<item android:state_enabled="true" android:drawable="@drawable/icon_play_inactive"/>

</selector>


布局中:


 <ImageButton

                android:layout_marginRight="15dp"

                android:background="@null"

                android:id="@+id/stop"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:src="
@drawable/music_stop_style" />

            <ImageButton

                android:id="@+id/play"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:background="@null"

                android:layout_marginRight="15dp"

                android:layout_marginLeft="15dp"

                android:src="
@drawable/music_play_style" />

<ImageButton

                android:layout_marginLeft="15dp"

                android:id="@+id/pause"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:background="@null"

                android:src="@
drawable/music_pause_style" />



代码中:
public void onClick(View arg0) {


// TODO Auto-generated method stub


switch (arg0.getId()) {


case R.id.stop:


stop.setSelected(true);


play.setSelected(false);


pause.setSelected(false);


break;


case R.id.play:


stop.setSelected(false);


play.setSelected(true);


pause.setSelected(false);


break;


case R.id.pause:


stop.setSelected(false);


play.setSelected(false);


pause.setSelected(true);


break;


     处理好即可、。

android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现的更多相关文章

  1. Android——selector背景选择器的使用详解(二)

    在开发应用中,很多情况下要设计listview或button控件的背景,下面总结一下android的selector的用法:1.在drawable中配置Android的selector.将如下的XML ...

  2. Android selector背景选择器

    selector根据不同的选定状态来定义不同的现实效果 常用属性: android:state_selected--------选中 android:state_focused--------获得焦点 ...

  3. Android中selector背景选择器

    http://blog.csdn.net/forsta/article/details/26148403 http://blog.csdn.net/wswqiang/article/details/6 ...

  4. Android:关于背景选择器Selector的item顺序

    在使用背景选择器的时候,如果item的顺序不对,会导致不起作用. 1.首先背景选择器的normal选项一定要放在最后. 2.pressed的选择器应该在seclet的前面.我在使用的时候找了半天问题, ...

  5. Android View 背景选择器编写技巧

    在项目中选择器的使用是非常多的,以下是本人在项目中的一些常用的背景选择器的写法 带边框下划线背景选择器效果图: 上面布局中放了10个CheckBox,然后设置了CheckBox的背景图片位,背景选择器 ...

  6. android中的selector背景选择器的用法

    关于listview和button都要改变android原来控件的背景,在网上查找了一些资料不是很全,所以现在总结一下android的selector的用法. 首先android的selector是在 ...

  7. Android的selector 背景选择器

    关于listview和button都要改变android原来控件的背景,在网上查找了一些资料不是很全,所以现在总结一下android的selector的用法.首先android的selector是在d ...

  8. [转]永久告别Android的背景选择器Selector!无需切很多图了!

    package com.zoke.custom.autobg; import android.content.Context; import android.content.res.TypedArra ...

  9. Android:res之selector背景选择器

    selector根据不同的选定状态来定义不同的现实效果 常用属性: android:state_selected--------选中android:state_focused--------获得焦点a ...

随机推荐

  1. 玩转AWS CloudWatch微信告警

    做海外业务时大多使用亚马逊 AWS 服务,配套AWS 监控 CloudWatch 功能强大,如果能和微信结合就更棒了.现在分享下如何玩转 CloudWatch 微信通知. AWS EC2 云主机配套的 ...

  2. CF 279A. Point on Spiral

    http://codeforces.com/problemset/problem/279/A 题意 :就是给你一个螺旋形的图,然后给你一个点,问从(0,0)点到这个点需要转几次弯,当然,是按着这个螺旋 ...

  3. linux登录后出现_bash-4.1#终端提示符异常

    如果使用root用户登录出现上述提示,则需要需要重建 /root .bash_profile文件: 1. vi /root .bash_profile 2. 输入如下内容 # .bashrc # Us ...

  4. grab jpegs from v4l2 devices

    某些平台下opencv不能直接直接支持摄像头获取图片或视频,这是需要使用v4l2(video for linux 2) 测试v4l2是否可以读到摄像头的内容,最简单的办法就是读取一张截图. v4l2g ...

  5. JAVA 字符串编码总结

    java 为了解决跨平台,字符串编码的有点特殊 String newStr = new String(oldStr.getBytes(), "UTF-8");java中的Strin ...

  6. 【大话QT之十】实现FTP断点续传(需要设置ftp服务器为“PASV”被动接收方式)

    应用需求: 网盘开发工作逐步进入各部分的整合阶段,当用户在客户端修改或新增加一个文件时,该文件要同步上传到服务器端对应的用户目录下,因此针对数据传输(即:上传.下载)这一块现在既定了三种传输方式,即: ...

  7. [Android] 修改设备访问权限

    在硬件抽象层模块中,我们是调用open函数来打开对应的设备文件的.例如,在2.3.2小节中开发的硬件抽象层模块freg中,函数freg_device_open调用open函数来打开设备文件/dev/f ...

  8. Nagios ’status.cgi‘文件权限许可和访问控制漏洞

    漏洞名称: Nagios ’status.cgi‘文件权限许可和访问控制漏洞 CNNVD编号: CNNVD-201307-013 发布时间: 2014-02-21 更新时间: 2014-02-21 危 ...

  9. -_-#【减少 DOM 访问】“离线”更新节点,再将它们添加到树中

    Minimize DOM Access javascript 之 DOM 优化 <!DOCTYPE html> <html> <head> <meta cha ...

  10. web移动开发最佳实践之html篇

    一.前言 在目前的移动应用开发大潮下,使用web技术进行移动应用开发正变得越来越流行,它主要使用html5.css3.js等技术,在跨平台性.可移植性方面具有无可比拟的优势,特别适合开发对性能要求不太 ...