Reputation: 135
I have a problem with WebView
, I use zsseditor with WebView
to show, input text from keyboard, insert image or video. And then, I can't delete newest letter in paragraph (almost I can't delete image html tag). And I solved that problem by CustomWebview to delete image html tags.
public class CustomWebView extends WebView {
/**
* Constructs a new WebView with a Context object.
*
* @param context a Context object used to access application assets
*/
public CustomWebView(Context context) {
super(context);
}
/**
* Constructs a new WebView with layout parameters.
*
* @param context a Context object used to access application assets
* @param attrs an AttributeSet passed to our parent
*/
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Constructs a new WebView with layout parameters and a default style.
*
* @param context a Context object used to access application assets
* @param attrs an AttributeSet passed to our parent
* @param defStyle the default style resource ID
*/
public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
// http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection
// http://stackoverflow.com/questions/164991Image78/cant-get-backspace-to-work-in-codemirror-under-phonegap-on-android-4-x
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new MyCustomInputConnection(this, false);
}
public class MyCustomInputConnection extends BaseInputConnection {
public MyCustomInputConnection(View targetView, boolean fullEditor) {
super(targetView, fullEditor);
}
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
// magic: in latest Android, deleteSurroundingText(1, 0) will be called for backspace
if (beforeLength == 1 && afterLength == 0) {
// backspace
return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
&& super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
}
return super.deleteSurroundingText(beforeLength, afterLength);
}
}
}
I swap input keyboard to Japanese, Vietnamese, Thai or every language not Alphabet. But when I tap button letter on keyboard, it doesn't show on WebView
. So how can I fix the WebView
which can show letter with every language?
Upvotes: 0
Views: 588
Reputation: 158
I have error same problem with you and solve with this code you just override inside your webview
```
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
outAttrs.actionLabel = null;
outAttrs.inputType = InputType.TYPE_NULL;
final InputConnection con = new BaseInputConnection(this,false);
public_con = new InputConnectionWrapper(
super.onCreateInputConnection(outAttrs), true) {
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
if (beforeLength == 1 && afterLength == 0) {
return this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
&& this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
}
return super.deleteSurroundingText(beforeLength, afterLength);
}
@Override
public boolean sendKeyEvent(KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_DEL){
return con.sendKeyEvent(event);
}else {
return super.sendKeyEvent(event);
}
}
};
try {
return public_con ;
}catch (Exception e){
return super.onCreateInputConnection(outAttrs) ;
}
}
```
Upvotes: 1