读书人

便利好用的自定义按钮按下效果

发布时间: 2013-07-09 09:50:47 作者: rapoo

方便好用的自定义按钮按下效果

public static StateListDrawable getClickableDrawable(Context context, Drawable drawable){ColorDrawable maskDrawable = new ColorDrawable(Color.parseColor("#7de2e2e2"));//EEEEE0LayerDrawable pressDrawable = new LayerDrawable(new Drawable[]{drawable, maskDrawable});return MyView.getBackground(drawable, pressDrawable);}private static class MyView extends View {public MyView(Context context) {super(context);}public static StateListDrawable getBackground(Drawable normal,Drawable pressed) {StateListDrawable stateListDrawable = new StateListDrawable();stateListDrawable.addState(View.PRESSED_ENABLED_STATE_SET, pressed);stateListDrawable.addState(View.ENABLED_FOCUSED_STATE_SET, pressed);stateListDrawable.addState(View.ENABLED_STATE_SET, normal);stateListDrawable.addState(View.FOCUSED_STATE_SET, pressed);stateListDrawable.addState(View.EMPTY_STATE_SET, normal);return stateListDrawable;}}

?

读书人网 >移动开发

热点推荐