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. python、matlab、c++的括号增加次序,以及图片存储方式

    1 增加次序: python:(同c++多维数组) np.zeros([2,3,4]),先是按照内存空间均分为2份,每份又均分3份,最终再细分4份            2最大份,先按左分 例子:re ...

  2. C++学习笔记31:术语翻译

    reference:引用 dereference:引领,好于"解引用" type:型式,好于"类型" int:整数型式,简称整型 class:类型式,简称类型 ...

  3. SpringMVC笔记

    Struts1是采用单例模式的,在并发访问中出来资源混乱,于是出现Struts2被设计为多例的解决并发产生的 数据混乱由于Struts2引入了值栈,拦截器,OGNL等,,,是访问速度下降在原生的JSP ...

  4. 4-Spark高级数据分析-第四章 用决策树算法预测森林植被

    预测是非常困难的,更别提预测未来. 4.1 回归简介 随着现代机器学习和数据科学的出现,我们依旧把从“某些值”预测“另外某个值”的思想称为回归.回归是预测一个数值型数量,比如大小.收入和温度,而分类则 ...

  5. mysql 数据库基本概念

    mysql 数据库基本概念 一.数据库的集中控制优点1.降低存储数据的冗余度2.更高的数据一致性3.存储的数据可以共享4.可以建立数据库所遵循的标准5.便于数据维护完整性6.能够实现数据的安全性 二. ...

  6. 学习 Local Sensitive Hash

    1. 最近邻法的应用 1.1 Jaccard 相似集 如何定义相似:即相关属性交集的大小,越大则越相似.我们给相似一个数学上的定义:Jaccard 相似集. 集合 \(S\) 与集合 \(T\) 的 ...

  7. Git 基础

    取得项目的 Git 仓库 有两种取得 Git 项目仓库的方法.第一种是在现存的目录下,通过导入所有文件来创建新的 Git 仓库.第二种是从已有的 Git 仓库克隆出一个新的镜像仓库来. 在工作目录中初 ...

  8. org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection 原因

    org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection 可能出现的原因     ...

  9. h5和h4区别图片

  10. Shiro中的subject.login()

    当调用ShiroHandler中的subject.login()的时候,会自动调用Realm中的doGetAuthenticationInfo方法.