android - 为什么 html5 功能在我的 android 应用程序中不起作用?

标签 android html

我想使用 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/

相关文章:

javascript - Safari 中的 SVG 过滤器 : x, y、宽度、高度未应用

Android FTP 错误 - 425 无法打开数据连接

android - Android中Mysql连接ListView的教程

android - ajaxSuccess之后无法获取getCurrentUser()

android - 在第一个 Activity 中从 editText 添加两个数字并在第二个 Activity 中显示答案?

android - 制作一个带有可点击对象的 2D 可滚动表格

javascript - 带有悬停状态问题的 Chrome 动画 CSS3 3D 立方体

javascript - DIV on hover - 让它可以悬停并改变它的不透明度,不闪烁

php - txt/word/excel 文件的 Html 表单答案

javascript - JQuery UI Datepicker - 如何在鼠标悬停时突出显示所选日期之前/之后的天数?