本文主要是介绍通过cordova+contentEditable开发hybird app时,输入框中backspace无反应的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
近日在通过cordova+contentEditable开发富文本编辑器,但是在虚拟机中测试的好好的到了真机中点击backspace却不能删除图片,必须点一下换行键,再把光标移回上面图片后面才可以。解决方法如下:
在org.apache.cordova包中创建CordovaInputConnection类
package org.apache.cordova;import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.BaseInputConnection;
public class CordovaInputConnection extends BaseInputConnection{public CordovaInputConnection(View targetView, boolean fullEditor) {super(targetView, fullEditor);}@Overridepublic boolean deleteSurroundingText(int beforeLength, int afterLength) { // magic: in latest Android, deleteSurroundingText(1, 0) will be called for backspaceif (beforeLength == 1 && afterLength == 0) {// backspacereturn 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);}}
@Overridepublic InputConnection onCreateInputConnection(EditorInfo outAttrs) {CordovaInputConnection connection = new CordovaInputConnection(this, false);return connection;}
就可以解决无效的问题
代码下载
最近发现使用contentEditable做文本编辑器会出现输入中文异常的问题,所以就改为native的方式实现,使用了一个开源的框架,见https://github.com/xmuSistone/android-animate-RichEditor
这篇关于通过cordova+contentEditable开发hybird app时,输入框中backspace无反应的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!