我正在覆盖按钮类中的 onDraw。
我怎么知道在 onDraw 中按下了按钮?
最佳答案
在 Button 的 onDraw(..)
方法中,您可以简单地检查 this.isPressed()
当您按下按钮时,这应该返回 true
。
编辑:
您还可以在 Button 的子类
中实现触摸事件:
示例:
public class tempButton extends Button {
public tempButton(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
//Button Pressed, Change the color of your Button here.
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
break;
}
return true;
}
}
希望对您有所帮助。
关于android - 如何在 MyButton::OnDraw 中知道状态被按下(聚焦),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21316214/