由网友(痴情痴梦痴心痴狂 べ)分享简介:有没有办法得到一个onButtonDown或onButtonUp事件的软按钮(即不是一个物理硬件按钮,但屏幕上的按钮)?我有,我希望用户按住X秒,屏幕上的按钮。要做到这一点,我需要单独捕获的buttonDown和buttonUp事件。谢谢布雷特解决方案 yourButton.setOnTouchListener(...![android中gridview里怎么添加button按钮啊](https://p.xsw88.cn/allimgs/daicuo/20230906/1928.png)
有没有办法得到一个onButtonDown或onButtonUp事件的软按钮(即不是一个物理硬件按钮,但屏幕上的按钮)?我有,我希望用户按住X秒,屏幕上的按钮。要做到这一点,我需要单独捕获的buttonDown和buttonUp事件。
谢谢
布雷特
解决方案 yourButton.setOnTouchListener(yourListener);
公共布尔onTouch(查看yourButton,MotionEvent theMotion){
开关(theMotion.getAction()){
案例MotionEvent.ACTION_DOWN:打破;
案例MotionEvent.ACTION_UP:打破;
}
返回true;
}
Is there a way to get an onButtonDown or onButtonUp event for a soft button (i.e. not a physical hardware button, but a button on the screen)? I have a button on the screen that I want the user to hold down for X seconds. To do this I need to capture the buttonDown and buttonUp events separately.
![android中gridview里怎么添加button按钮啊](https://p.xsw88.cn/allimgs/daicuo/20230906/1928.png)
Thanks,
Bret
解决方案yourButton.setOnTouchListener( yourListener );
public boolean onTouch( View yourButton , MotionEvent theMotion ) {
switch ( theMotion.getAction() ) {
case MotionEvent.ACTION_DOWN: break;
case MotionEvent.ACTION_UP: break;
}
return true;
}
相关推荐
最新文章