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

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

阅读更多
public static StateListDrawable getClickableDrawable(Context context, Drawable drawable){
		ColorDrawable maskDrawable = new ColorDrawable(Color.parseColor("#7de2e2e2"));//EEEEE0
		LayerDrawable 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;
		}
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics