2424import android .view .View ;
2525import android .view .ViewGroup ;
2626import android .view .inputmethod .EditorInfo ;
27+ import android .view .inputmethod .InputConnection ;
28+ import android .view .inputmethod .InputConnectionWrapper ;
2729import android .widget .TextView ;
2830
2931import java .util .ArrayList ;
@@ -1094,5 +1096,31 @@ public boolean onTouchEvent(MotionEvent event) {
10941096 }
10951097 return true ;
10961098 }
1099+
1100+ @ Override
1101+ public InputConnection onCreateInputConnection (EditorInfo outAttrs ) {
1102+ return new ZanyInputConnection (super .onCreateInputConnection (outAttrs ), true );
1103+ }
1104+
1105+ /**
1106+ * Solve edit text delete(backspace) key detect, see<a href="http://stackoverflow.com/a/14561345/3790554">
1107+ * Android: Backspace in WebView/BaseInputConnection</a>
1108+ */
1109+ private class ZanyInputConnection extends InputConnectionWrapper {
1110+ public ZanyInputConnection (android .view .inputmethod .InputConnection target , boolean mutable ) {
1111+ super (target , mutable );
1112+ }
1113+
1114+ @ Override
1115+ public boolean deleteSurroundingText (int beforeLength , int afterLength ) {
1116+ // magic: in latest Android, deleteSurroundingText(1, 0) will be called for backspace
1117+ if (beforeLength == 1 && afterLength == 0 ) {
1118+ // backspace
1119+ return sendKeyEvent (new KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_DEL ))
1120+ && sendKeyEvent (new KeyEvent (KeyEvent .ACTION_UP , KeyEvent .KEYCODE_DEL ));
1121+ }
1122+ return super .deleteSurroundingText (beforeLength , afterLength );
1123+ }
1124+ }
10971125 }
10981126}
0 commit comments