2012-07-12 94 views
1

我正在試圖製作一個帶有webview的Android應用程序,其中有一個html頁面。這一個包含一個contentEditable屬性設置爲true的「div」標記。在webview中編輯div標籤

我的問題:通過啓動應用程序,我無法編輯文本。

我一直在谷歌上進行大量搜索,但這個話題沒有任何內容。我想知道是否有任何權限丟失(作爲到達清單中的網絡的權限),但我可以編輯輸入和textarea標籤(等等)。我已經提到了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" /> 

回答

1

contentEditable是在Android 3.0版的默認瀏覽器支持(蜂窩)和(source)。

所以,如果你在薑餅上運行這個,這將解釋爲什麼它不起作用。

+0

我在Froyo(2.2)上運行我的應用程序,現在它正在工作。我在代碼中添加了一個OnKeyListener,它阻止了div標籤的版本,我不知道爲什麼。例如,現在我不知道如何聽輸入鍵。 感謝您的回答。 – user1521019 2012-07-13 08:18:40

+0

那麼,你說你有'contenteditable'來處理2.2?怎麼樣?我試圖讓它在我們的應用程序中工作,以支持舊手機的用戶。 – Erhannis 2013-09-12 18:48:30