码迷,mamicode.com
首页 > 移动开发 > 详细

android 代码生成selector drawable

时间:2015-10-20 11:51:56      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

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测试

android 代码生成selector drawable

标签:

原文地址:http://www.cnblogs.com/songsyl1207/p/4894105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!