android 代码生成selector drawable
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的更多相关文章
- Android的selector,背景选择器
原文地址 http://android.blog.51cto.com/268543/564581 首先android的selector是在drawable/xxx.xml中配置的,相关图片放在同目录下 ...
- 浅谈android的selector,背景选择器
shape和selector的结合使用 (2013-04-07 11:11:00) 转载▼ 分类: android 1.Shape (1)作用:XML中定义的几何形状 (2)位置:res/draw ...
- Android的selector 背景选择器
关于listview和button都要改变android原来控件的背景,在网上查找了一些资料不是很全,所以现在总结一下android的selector的用法.首先android的selector是在d ...
- Android中各种Drawable总结
在Android中,Drawable使用广泛,但是种类也多,基于<Android开发艺术探索>中对Drawable的讲解,总结了如下表格.
- Android中Bitmap, Drawable, Byte,ID之间的转化
Android中Bitmap, Drawable, Byte,ID之间的转化 1. Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...
- Android中的Drawable和动画
Android中Drawable是一种可以在Canvas上进行绘制抽象的概念,种类很多,常见的颜色和图片都可以是一个Drawable.Drawable有很多种,它们表示一种图像的概念,但是它们又不全是 ...
- Android下的Drawable使用
Drawable表示一种可绘制的内容,可以由图片或者颜色组成.Android下的Drawable有BitmapDrawable.GradientDrawable.LayerDrawable等等 1.B ...
- Android的各种Drawable 讲解 大全
Android把可绘制的对象抽象为Drawable,不同的图形图像资源就代表着不同的drawable类型.Android FrameWork提供了一些具体的Drawable实现,通常在代码中都不会直接 ...
- Android RadioButton selector背景
RadioButton selector 背景 <?xml version="1.0" encoding="utf-8"?> <selecto ...
随机推荐
- editor does not contain a main type的解决方案
editor does not contain a main type的解决方案 今天用eclipse,当打算run一个带有main函数的class时,出现editor does not contai ...
- iOS--cell的重用机制
对于像我们这样的初学者来说,cell重用机制是很难理解的内容,所以我们不一定非得理解,会用就行. cell的重用机制:当我们使用tableView时,系统只会创建屏幕中显示的cell的个数+1,当ce ...
- Apache2 同源策略解决方案 - 配置 CORS
什么是同源策略 现在的浏览器大多配有同源策略(Same-Origin Policy),具体表现如下: 浏览某一网站,例如 http://www.decembercafe.org/.这个网页中的 Aja ...
- folly::AtomicHashmap源码分析(二)
本文为原创,转载请注明:http://www.cnblogs.com/gistao/ 背景 上一篇只是细致的把源码分析了一遍,而源码背后的设计思想并没有写,设计思想往往是最重要的,没有它,基本无法做整 ...
- IOS开发网络数据---- AFNetworking的使用
http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...
- Linux Command Line 笔记(1)
Yunduan CUI graphical user interfaces make easy tasks easy, while command line interfaces make diffi ...
- X86 Socket 通信
struct txd_socket_handler_t { int fd; }; txd_socket_handler_t *txd_tcp_socket_create() { txd_socket_ ...
- 使用游戏引擎photon打造一款特殊的远程控制软件
前言 本文主要是介绍photon引擎的一些基本用法,以及使用游戏引擎开发远控的优势 0x1 有一段时候对做游戏的unity开发有些兴趣,在找游戏服务端引擎的时候,突然发现了这款歪果人开发的游戏引擎ph ...
- Quant的笑话
Q) Why was the FX quant so unlucky with the ladies?A) Because he always kept his dates short. Q) Why ...
- WAMPSERVER PHP版本5.3的降到 5.2?
在这里下载5.2版本PHP,http://sourceforge.net/projects/wampserver/files/WampServer%202%20-%20Extensions/PHP/下 ...