相关疑难解决方法(0)

Clickevents在web视图android中不起作用

我必须在android中创建我们的应用程序.

所以我做的是,只需在res下创建原始文件夹并将html文件放在那里.

一切正常,但当我点击一个放在该网页内的按钮时没有任何反应,并且点击事件无法正常工作.

这是我的代码.

newfile.html

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form>
<input type="button" value="Click me" onclick="openDialog()">
<script>
function openDialog()
{

alert("ok");
}
</script>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的java代码,

webview.loadData(readTextFromResource(R.raw.newfile),"text/html", "utf-8");
Run Code Online (Sandbox Code Playgroud)

readTextFromResource函数

    private String readTextFromResource(int resourceID)

{
    InputStream raw = getResources().openRawResource(resourceID);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    int i;
    try
    {
        i = raw.read();
        while (i != -1)
        {
           stream.write(i);
            i = raw.read();
        }
        raw.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
return …
Run Code Online (Sandbox Code Playgroud)

html javascript android webview

2
推荐指数
1
解决办法
5564
查看次数

标签 统计

android ×1

html ×1

javascript ×1

webview ×1