首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

很久发博客了,发个不久前写的一个方法吧

2012-08-03 
很久发博客了,发个最近写的一个方法吧。/** * 设定按钮动作 * @param normal * @param press * @param btn

很久发博客了,发个最近写的一个方法吧。

/** * 设定按钮动作 * @param normal * @param press * @param btn */private StateListDrawable getPressableDrawable(Context context, Drawable normal, Drawable pressed){MyView myButton = new MyView(context);return myButton.getBackground(normal, pressed);}private class MyView extends View{public MyView(Context context) {super(context);}public 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;        }}

?设置imageView按下效果的方法。

热点排行