`
yangzc106
  • 浏览: 156678 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

 
阅读更多
/**
	 * 设定按钮动作
	 * @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按下效果的方法。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics