如何检测用户是否点击Android键盘中的sym或表情符号按钮?

时间:2015-09-24 09:26:02

标签: android keyboard keycode

我一直在使用dispatchKeyEvent来获取Android键盘的键码,但问题是当我点击Sym或Emoji按钮时没有任何事情发生,没有键码显示。这是我用来获取密码的代码:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    Toast.makeText(getBaseContext(), "key pressed : "+ String.valueOf(event.getKeyCode()), Toast.LENGTH_SHORT).show();
    return super.dispatchKeyEvent(event);
}

1 个答案:

答案 0 :(得分:0)

对表情符号使用KeyEvent.KEYCODE_PICTSYMBOLS。

/*
     * Respond to soft keyboard events, look for the DONE press on the password field.
     */
    public boolean onKey(View v, int keyCode, KeyEvent event)
    {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
            (keyCode == KeyEvent.KeyEvent.KEYCODE_PICTSYMBOLS))
        {
            // Done pressed!  Do something here.
        }
        // Returning false allows other listeners to react to the press.
        return false;
    }