public static StateListDrawable makeSelector(Context context, int idNormal, int idPressed, int idFocused) {
StateListDrawable bg = new StateListDrawable();
Drawable normal = context.getResources().getDrawable(idNormal);
Drawable pressed = context.getResources().getDrawable(idPressed);
Drawable focused = context.getResources().getDrawable(idFocused);
bg.addState(new int[]{android.R.attr.state_pressed,}, pressed);
bg.addState(new int[]{android.R.attr.state_focused}, focused);
bg.addState(new int[]{}, normal);
return bg;
} 注意: 1.normal state要在最后add
2.使用button测试,ImageView 需要设置clickable为true

android 代码生成selector drawable的更多相关文章

  1. Android的selector,背景选择器

    原文地址 http://android.blog.51cto.com/268543/564581 首先android的selector是在drawable/xxx.xml中配置的,相关图片放在同目录下 ...

  2. 浅谈android的selector,背景选择器

    shape和selector的结合使用 (2013-04-07 11:11:00) 转载▼   分类: android 1.Shape (1)作用:XML中定义的几何形状 (2)位置:res/draw ...

  3. Android的selector 背景选择器

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

  4. Android中各种Drawable总结

    在Android中,Drawable使用广泛,但是种类也多,基于<Android开发艺术探索>中对Drawable的讲解,总结了如下表格.

  5. Android中Bitmap, Drawable, Byte,ID之间的转化

    Android中Bitmap, Drawable, Byte,ID之间的转化 1.  Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...

  6. Android中的Drawable和动画

    Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...

  7. Android下的Drawable使用

    Drawable表示一种可绘制的内容,可以由图片或者颜色组成.Android下的Drawable有BitmapDrawable.GradientDrawable.LayerDrawable等等 1.B ...

  8. Android的各种Drawable 讲解 大全

    Android把可绘制的对象抽象为Drawable,不同的图形图像资源就代表着不同的drawable类型.Android FrameWork提供了一些具体的Drawable实现,通常在代码中都不会直接 ...

  9. Android RadioButton selector背景

    RadioButton selector 背景 <?xml version="1.0" encoding="utf-8"?> <selecto ...

随机推荐

  1. SqlServer不能将text列类型更改为ntext的问题

    可以先将text类型更改为nvarchar,在将nvarchar更改为ntext即可. alter db_note alter column [content] nvarchar; alter db_ ...

  2. 关于Ciarlet的泛函的一道homework的一个想法

    [转载请注明出处]http://www.cnblogs.com/mashiqi 2016/11/21 有一道题是证明$(\mathbb{R}^n,\|\cdot\|_p)$当$p : 1< p ...

  3. windows 下 putty 登陆服务器 显示matlab图形界面

    本文需要下载 putty.exe 和 pscp.exe :http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Xming 主 ...

  4. UML(一) 类图及类间关系

    原创文章,同步发自作者个人博客,http://www.jasongj.com/uml/class_diagram/ UML类图 UML类图介绍 在UML 2.*的13种图形中,类图是使用频率最高的UM ...

  5. Flask 的扩展

    1. Flask-Script,为Flask程序提供了一个命令行解析器: (venv) $ pip install flask-script 2. Bootstrap(http://getbootst ...

  6. Dos学习笔记(1)dir命令

    这个命令是最常用的命令,就像linux的ls一样,同样他也有很多很多optionnal field供我们选择, 看了半天,觉得自己离盲打肯定还是有很大的差距的,现在只是想体验一下dos,或者说感受下这 ...

  7. mysql之替换字符串

    update `wp_posts` set `post_content`=REPLACE(`post_content`,'localhost/linkcp','www.linkcp.cn') wher ...

  8. 【转载】ANSYS完全法与模态叠加法瞬态分析实例

    原文地址:http://www.caetecc.com/thread-2172-1-1.html ! 半脉冲载荷 --- 模态叠加法fini/clear,nostart/PREP7ET,1,BEAM4 ...

  9. Opencv-Python 学习

    加载一个灰度图,显示图片,按下’s’键保存后退出,或者按下 ESC 键退出不保存. import numpy as np import cv2 img = cv2.imread('linux.png' ...

  10. Linux测试环境部署jdk(一)

    安装配置JDK yum install -y lrzsz  安装rz,方便xshell上传下载文件 Jdk: jdk-6u1-linux-i586 Tomcat: apache-tomcat-7.0. ...