如何实现的onkeydown事件在Android中自定义按钮 [英] how implement onkeydown event for custom buttons in android

查看:263
本文介绍了如何实现的onkeydown事件在Android中自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的布局定义的按钮,我实现的onclick按钮没有问题,但现在我需要知道什么时候我的按钮是doww最多,像fisical按键的onkeydown事件。有这样的事情海关按钮??。由于的onkeydown(INT键code,KeyEvent的事件)有一个INT键code,但MUY自定义按钮都没有。
我希望有人能带走查询。
预先感谢您

I have a button defined in my layout, I implement onclick buttons without problems, but now I need to know when my button is doww and up, like onkeydown event for fisical buttons. There is something like that for customs buttons??. Because onKeyDown (int keyCode, KeyEvent event) have a int keycode but muy custom button haven't. I hope someone can take away that query. thank you in advance

推荐答案

是的,有。试试这个code。

Yes there is. try this code.

    yourButton.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {

               switch ( event.getAction() ) {
                case MotionEvent.ACTION_DOWN: break;
                case MotionEvent.ACTION_UP: break;
                }
                return true;
        }
    });

这篇关于如何实现的onkeydown事件在Android中自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆