我想要处理html文件,我在部署它的时候做了,它不会工作(输入的html页面需要显示,但它显示网页在我部署时不可用)!错误消息也不在日志中!任何帮助请。我做错了什么?
public class TestActivity extends Activity {
/** Called when the activity is first created. */
WebView webView =null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView =(WebView)findViewById(R.id.web);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android-assets/www/index.html");
}
}这是我的javascript。
function sayhello(){
alert("hi", document.getElementById('name'),value);
}和html文件在这里
<!DOCTYPE html>
<html>
<head>
<script src="index.js"></script>
</head>
<body>
What is ur name ?
<input id="name" value="">
<button onclick="sayhello()">say hello</button>
</body>
</head>
</html>和布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/web"
android:text="@string/hello"
/>
</LinearLayout>发布于 2012-09-18 02:35:04
您需要使用:
file:///android-asset/www/index.html去掉“s”就行了
更新:
您还可以使用以下命令加载页面:
webView.loadDataWithBaseURL(null, html, "text/html", "utf-8",null);其中第二个参数是要加载的页面。
https://stackoverflow.com/questions/12464670
复制相似问题