/**
* 设定按钮动作
* @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按下效果的方法。
本文介绍了一种使用StateListDrawable为按钮设置按下效果的方法。通过定义不同状态下的Drawable资源,实现按钮在不同交互状态下的视觉反馈。
7万+

被折叠的 条评论
为什么被折叠?



