问题
Problem: Can't delete image in contenteditable div on Android
Only known solution at the moment: Android: Backspace in WebView/BaseInputConnection
Problem with solution: Setting: creating a BaseInputConnection using the regular constructor seems to disable speech to text from functioning correctly. as opposed to using WebView.onCreateInputConnection(EditorInfo) to generate an InputConnection.
any ideas how to remedy this?
回答1:
I had the same issue also with text completion using SwiftKey. In order to fix it you must remember some things:
- you must extend BaseInputConnection and wrap the original webview's InputConnection
- don't use InputConnectionWrapper as it will cause other problems
you need to subclass a second method: commitText
public boolean commitText(CharSequence text, int newCursorPosition) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { return orig.commitText(text, newCursorPosition); } else { // pre-kitkat workaround boolean res = true; for (int i = 0; i < text.length(); i++) { res = orig.commitText(text.subSequence(i, i+1), newCursorPosition); } return res; } }
来源:https://stackoverflow.com/questions/24704540/android-webview-strategy-for-deleting-images-causing-speech-to-text-to-fail