Button没这种功能,简单的做法是派生一个自己的Button比如
public class MyButton extends Button{
private boolean _pressed = false;
//把三个构造方法都实现了
public MyButton(Context context){
}
public MyButton(Context context, AttributeSet attrs){
}
public MyButton(Context context, AttributeSet attrs, int defStyle){
}
//覆写dispatchTouchEvent方法
@Override
public boolean dispatchTouchEvent(MotionEvent event){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
_pressed = true;
break;
case MotionEvent.Action_UP:
_pressed = false;
break;
}
return super.dispatchTouchEvent(event);
}
//提供查询是否按下
public boolean checkPress(){
return _pressed;
}
}