我想制作一个网页 View 计算器。让我有一个 HTML 基本计算器 UI。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<link href='https://fonts.googleapis.com/css?family=Orbitron' rel='stylesheet' type='text/css'>
</head>
<body>
<form action="" name="calc">
<input type="text" name="screen" disabled> <br>
<hr>
<input type="button" value="√" onclick="calc.screen.value = Math.sqrt(calc.screen.value);">
<input type="button" value="CE" onclick="calc.screen.value = ''">
<input type="button" value="C" onclick="calc.screen.value = ''">
<input type="button" value="←" onclick="calc.screen.value = calc.screen.value.slice(0,-1);"> <br>
<input type="button" value="7">
<input type="button" value="8">
<input type="button" value="9">
<input type="button" value="+">
<br>
<input type="button" value="4">
<input type="button" value="5">
<input type="button" value="6">
<input type="button" value="-">
<br>
<input type="button" value="1">
<input type="button" value="2">
<input type="button" value="3">
<input type="button" value="*">
<br>
<input type="button" value="0">
<input type="button" value=".">
<input type="button" value="=">
<input type="button" value="/"> <br>
</form>
</body>
</html>
现在,我想从按钮获取值,然后在 android java 类中进行计算。之后,最终结果将以 HTML 形式显示。
如何将输入类型的值从 HTML 获取到 android 并传回?
最佳答案
您需要使用 Android JavaScriptInterface 类从 html 输入字段获取数据。
JavaScriptInterface 有 processFormData() 方法以字符串形式返回数据。
然后你就可以按照你想要的方式处理这些数据了。
你发现了一些example here
关于java - 获取从html到android的输入类型值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40602162/