我想使用 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>
最佳答案
你需要使用:
file:///android-asset/www/index.html
去掉's'
更新:
您还可以加载页面:
webView.loadDataWithBaseURL(null, html, "text/html", "utf-8",null);
第二个参数是要加载的页面。
关于android - 为什么 html5 功能在我的 android 应用程序中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12464670/