1
我試圖通過字符串的versionName到的WebView和我的HTML在頁面上顯示的字符串。這是我嘗試過的。傳遞字符串到的WebView和顯示
try {
myWebView.getSettings().setJavaScriptEnabled(true);
String versionName = getPackageManager()
.getPackageInfo("com.chad.flashupdate", 0)
.versionName;
myWebView.loadUrl("javascript:init('" + versionName + "')");
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
然後我試着用這個加載和顯示字符串。
$(document).ready(function() { $("#MyEdit").html(versionName); });
在我的html中,我把這個。
<div id="MyEdit"><B>
versionName will be displayed here!
</B></div>
當我嘗試沒有任何反應時,意味着div文本從不改變。所以也許webview不會加載字符串。謝謝你的幫助!
一個問題。當我加載webview它只顯示div。我如何可以加載在資產正常的HTML文件,並有該div換到了htmlString?當我添加你的代碼時,它只顯示加載的div。 –
這使事情變得更加複雜一點。有許多方法可以從文件中加載html,但將你的版本加入將會更加複雜。這裏是一個鏈接,獲取資源文件作爲一個字符串:http://stackoverflow.com/questions/16110002/read-assets-file-as-string。之後,我會尋找某個文本字符,然後用您擁有的版本替換它。 –