在 Android 4.x 上的 Phonegap 下,无法在 codemirror 中使用退格键?

编程入门 行业动态 更新时间:2024-10-27 10:28:09
本文介绍了在 Android 4.x 上的 Phonegap 下,无法在 codemirror 中使用退格键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用需要一个性能良好的基于​​网络的文本/代码编辑器.

I need a web-based text/code editor that behaves well, for my App.

我正在尝试在 Phonegap 下使用 codemirror,目前我在让退格键为以前输入的文本工作时遇到问题.这对我的用例来说是一个巨大的问题.现在我环顾四周,它似乎不是直接的 codemirror 问题,而是 android 和虚拟键盘问题,请参阅此问题:Android:WebView/BaseInputConnection 中的退格

I'm trying to use codemirror under Phonegap and currently I'm having problems getting backspace to work for previously entered text. This is a huge problem for my use case. Now I've had a look around and it seems like it's not a direct codemirror problem, but rather the android and virtual keyboard malarkey, see this question: Android: Backspace in WebView/BaseInputConnection

我正在使用 Phonegap 版本 2.6.0、最新的 codemirror 版本(截至昨晚)并在 Android 4.2.2 上进行测试.这似乎特定于 Android 上的 WebView,有人可以确认这在 iOS 上不是问题吗?

I'm using Phonegap version 2.6.0, latest codemirror version (as of last night) and testing on Android 4.2.2. This seems to be specific to WebView on Android, could anyone verify that's not an issue on iOS?

我并不反对编写一些 Java 代码来纠正问题,但我不确定如何挂钩"到 Cordova 的 WebView 实现中,因为我看到的所有代码都包括:

I'm not averse to doing some Java code to rectify the problem, but I'm not sure how to 'hook' into the cordova's implementation of WebView, as all the code that's exposed to me consists of:

package com.mycompany.MyAppName; import android.os.Bundle; import org.apache.cordova.*; public class MyAppName extends DroidGap{ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // Set by <content src="index.html" /> in config.xml super.loadUrl(Config.getStartUrl()); //super.loadUrl("file:///android_asset/www/index.html") } }

除非我应该查看 Cordovas 源代码树.基本上我想知道的是我如何在上面的链接中实施解决方案.非常感谢任何帮助!

unless I'm supposed to look into Cordovas source tree. Essentially what I want to know is how I can implement the solution at the link above in my case. Any help is greatly appreciated!

推荐答案

覆盖 init Activity 方法:

Override init Activity method :

public class ProjectName extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); init(); // Don't forget this, you'll get runtime error otherwise! // The following does the trick: super.appView.getSettings().setUseWideViewPort(true); super.appView.getSettings().setLoadWithOverviewMode(true); // Set by <content src="index.html" /> in config.xml super.loadUrl(Config.getStartUrl()); //super.loadUrl("file:///android_asset/www/index.html") super.setIntegerProperty("loadUrlTimeoutValue", 10000); } /** * Create and initialize web container with default web view objects. */ @Override public void init() { CordovaWebView webView = new CustomWebView(ProjectName.this); CordovaWebViewClient webViewClient; if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { webViewClient = new CordovaWebViewClient(this, webView); } else { webViewClient = new IceCreamCordovaWebViewClient(this, webView); } this.init(webView, webViewClient, new CordovaChromeClient(this, webView)); } }

在扩展 CordovaWebView 的 CustomWebView 上创建

Create on CustomWebView which extends CordovaWebView

public class CustomWebView extends CordovaWebView{ public CustomWebView(Context context) { super(context); } @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { MyCustomInputConnection connection = new MyCustomInputConnection(this, false); return connection; } }

创建您的自定义 InputConnection :

Create your custom InputConnection :

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); } }

更多推荐

在 Android 4.x 上的 Phonegap 下,无法在 codemirror 中使用退格键?

本文发布于:2023-11-17 17:06:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   Phonegap   退格键   codemirror

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!