【问题标题】:IME "Enter" key behave like "Send" in FB MessengerIME“Enter”键的行为类似于 FB Messenger 中的“Send”
【发布时间】:2019-04-27 10:20:18
【问题描述】:

在使用 FB Messenger 时,

在我的自定义键盘中,按“Enter”键 -> 发送消息。

但在谷歌键盘中,按“Enter”键 -> 换行。

如何按自定义键盘的“Enter”键进入新行?

                EditorInfo editorInfo = getCurrentInputEditorInfo();
                int imeOptions = editorInfo != null ? editorInfo.imeOptions : -77;
                switch (imeOptions & (EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
                    case EditorInfo.IME_ACTION_GO:
                        ic.performEditorAction(EditorInfo.IME_ACTION_GO);
                        break;
                    case EditorInfo.IME_ACTION_NEXT:
                        ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
                        break;
                    case EditorInfo.IME_ACTION_SEARCH:
                        ic.performEditorAction(EditorInfo.IME_ACTION_SEARCH);
                        break;
                    case EditorInfo.IME_ACTION_SEND:
                        ic.performEditorAction(EditorInfo.IME_ACTION_SEND);
                        break;
                    default:
                        // seems like passing here but sending the message
                        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
                        break;
                }

【问题讨论】:

  • 你好。我的回答有帮助吗?

标签: java android android-softkeyboard ime


【解决方案1】:

所以你可以做的就是听这样的按键按下:

 @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_ENTER){
        // Get the text in the TextView or whatever and append the "\n" to it.
        textView.setText(textView.getText.toString() + "\n");
    }
}

当一个键被按下时,它会监听,然后检查按下的键是否是Enter 键。然后,它通过执行\n 添加一个新行。我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-30
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    相关资源
    最近更新 更多