【问题标题】:edit div tag in a webview在 webview 中编辑 div 标签
【发布时间】:2012-07-12 14:22:27
【问题描述】:

我正在尝试制作一个带有 web 视图的 Android 应用程序,其中我有一个 html 页面。这个包含一个“div”标签,contentEditable 属性设置为 true。

我的问题:通过启动应用程序,我无法编辑文本。

我在 Google 上进行了大量搜索,但没有关于此主题的内容。我想知道是否缺少任何权限(作为清单中访问网络的权限),但我能够编辑输入和文本区域标签(等等)。我参考了 WebView 的 API、WebViewClient、WebChromeClient,但我没有找到任何可以配置特定权限的方法。

webview 是否理解 contentEditable 属性?它不起作用,即使 webview 应该解释 html。

我的活动:

public class WebAppStackOverFlowActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        WebView webView = (WebView) findViewById(R.id.webView) ;
        webView.setWebChromeClient (new WebChromeClient()) ;
        webView.loadUrl("file:///android_asset/www/index.html") ;
    }
}

我的asset/www/index.html 文件:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <input id="name" value="this is an input tag" />
    <br />
    <div contenteditable="true">this is an editable div tag</div>
    <br />
    <textarea rows="" cols="">this is a textarea tag</textarea>
</body>
</html>

我的main.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

【问题讨论】:

    标签: android webview


    【解决方案1】:

    Android 3.0 (Honeycomb) 及更高版本 (source) 上的默认浏览器支持contentEditable

    所以,如果你在 Gingerbread 上运行它,这就解释了为什么它不起作用。

    【讨论】:

    • 我在 Froyo (2.2) 上运行我的应用程序,现在它正在运行。我在我的代码中添加了一个 OnKeyListener 并且它阻止了 div 标签的版本,我不知道为什么。例如,现在我不知道如何听输入键。谢谢你的回答。
    • 那么,你说你有contenteditable 可以在 2.2 上工作?如何?我正在尝试让它在我们的应用中运行,以支持旧手机的用户。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 2011-02-17
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-16
    相关资源
    最近更新 更多