Android的 - 如何禁用搜索按钮长preSS(的Nexus One)按钮、Android、preSS、One

2023-09-05 10:09:16 作者:以可爱出名

Android的文档介绍了如何禁用搜索搜索功能活动: 公共布尔onSearchRequested(){     返回false;  }

The Android documentation describes how to disable the search the search feature in Activity: public boolean onSearchRequested() { return false; }

这工作正常的搜索按钮,在Nexus One上很短的preSS。 但是,它不会禁用长preSS,仍然触发了一个语音搜索。

This works fine for a short press of the search button on the Nexus One. However, it doesn't disable the long press, which still fires off a voice search.

我如何禁用长preSS语音搜索?

How do I disable the long press Voice search?

谢谢...

推荐答案

我伸出斯坦的答案,只禁用长preSS事件。

I extended Stan's answer to only disable long press events.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_SEARCH
        && (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) == KeyEvent.FLAG_LONG_PRESS) {
        return true;
    }

    return super.onKeyDown(keyCode, event);
}