How to delete a delete key - delete all selected editing text in a custom Android keyboard

I am creating a special keyboard for Android, and I want to delete the key to delete all the editing text, if selected.

ie, when text is selected, the clipboard is created (cut, copy, paste); in this mode, if the delete key is pressed, it should delete everything. This is currently not the case.

PS they don’t tell me about a specific text editor, this is a user keyboard, it will not have access to edit text.

+1
android android-softkeyboard android-input-method keyboard inputconnection
Jun 24 '16 at 3:10
source share
2 answers

I do not understand why this will not happen. I created on the keyboard, I just send a key removal event, and it works like a charm. Try the following when the delete / return key is pressed when something is selected.

getCurrentInputConnection().sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_DEL)); getCurrentInputConnection().sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_DEL)); 
+1
Nov 22 '16 at 19:18
source share

You can also see if there is InputConnection selected text with getSelectedText . Then delete it if it does (or delete the previous character if it does not).

 CharSequence selectedText = inputConnection.getSelectedText(0); if (TextUtils.isEmpty(selectedText)) { inputConnection.deleteSurroundingText(1, 0); } else { inputConnection.commitText("", 1); } 
0
Jul 20 '17 at 1:38 on
source share



All Articles