android基础---->WebView的使用
webView的使用
我们通过一个小的测试程序来体会webView的简单使用,项目结构如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASEAAAE2CAIAAAChrLNvAAAbCUlEQVR4nO2dzW/c5p3H56/orRcfeuqlhxYh0DUMN8EaG9gn72LbXIpglwskJ28goU52rWRRJG2aEMEGsNvYiwRdbLyBNDPySqHtWeXNI8QxrEhR7MjRKI6AtcYqECdSxhon08bgHjgkn5ffQ3I4fGb48v1gkGjI53lIjfnR85DD58vK6dOnnTR46+SjMV/DbqllGZVKxbBasUrbZqVSqZj2UFuLuzG2VtINgqJRYR2bn5+vUszNzUU2lFXHhsU2k2zMNit6dgfkD86xdrtNOtZutyMbiuOPVIY7gNkexzb5HyuVoKDvmLfGXc51WF6ZdbEfE1qL2IF/80sHbUj7wy2rmHb/XeQnBkpCRRgrNhoNQbBGoxGnoUSOscd4/zg1rJY/QFtnD17/OHf94ZB8CX6WxOFbC9+B06Jj0fsDx4CA6Fin06nVar5gtVqt0+nEaSiOY1vX39m6/g67xD0+vSPVMIzgUDasFieIf2LUP6a5bkWQTDLHtPkf/dYidiCkp/P3hxpNYqwIfETHHMdZXFz0HWs2mzEbCnHs2NnLwitYxx6phmWZ/oHP2CR0HPz5GPPO94W9ThFoEdKaagcc3jG6BbZzY2SM/U8ACg7hWK/Xq9frbifW6/ViNpTQMe8Yt0y/T3CP9MAK8YID148Rb0zLMoIzMNEx6fJF2A44lGP0BRBfNK/LjPm5gcJDOOY4zsrKSrVaXV1djd9QUsf6x7hhBB54bxzp/Me0HWVvwrUlXuQgz8fY6yOqHWDqEOdjzBBUWhb/owPFhnbMcZyFhYWBGlJdqd+6/k64YyH9ErNAcsztbNjxGVs6qM9fV5Rbi78D3HqFY/6+tKyBPj1QYJSODUpyxwAoNKk5FgIcA2VmFI4BUGbgGAB6gWMA6AWOAaAXOAaAXuAYAHqBYwDoBY4BoJdMOCZ/SX3h2q1x7xQA6ZBRx0atGTOZhbhlEYAhyK5j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/LmZ8w66mUG7k3IvonKuuGLYcuDaRHytc8FhcXfceazWbMWirHFpvvPv/cM+xrsfmuUIZKuRGCNKQldNYNKxZyb0BqpOxYr9er1+tuJxY/8TfhWJFOuWHWcZIwS+isG7oHhGlgSNK/dr+yslKtVldXV+NXSThWJFNu5MgaIsSGyrrhx4rIvQFpoeX7sYWFhYHKk5fpb16pT5/+dehYkUy5ISJriBCbkIslwjUQGAaGI7vfQd+8Uo++rghA5smEYyqirisCkAMy7RgABQCOAaAXOAaAXuAYAHqBYwDoBY4BoJciOHZGwfLy8rh3DYBCOzY9PQ3NwNgpjmPywm63OzMzA83AeCmUY/+88U/uy+E7N6IO81zMaMKeSaurJtMC7pjMN0Vz7O+tv3UdE1aJwDEwKorm2P4DB+XebNgNpOzYQPNl4FjugWMxgGNgCAro2P4DB/0RY+hY0c8mMCzLZEIHXPhAgmCFELbDPbmdm/spNV4xbSGcZ90tYPcns7HrvQ3CsdxTQMf8/zpxHfPECE7ShInS/iFPhu14S4lOi2xcCg4JtskW9tuGY/kGjgnaUIEf/ls6bMdfIQ8LqcZFx/wC5M9wLPfAsQEdo0/M4BhQUjTH2JeT2DFurMjGX5FhO/0m+MGgLCUcKymFcmyAVRGO8Zc2LOEsTMpzZALoKqYd5VgQzrMOx0pAcRwLYdw7CEoNHANAL0VwDIAsA8cA0AscA0AvcAwAvcAxAPTy/7FZV1+Jr7CuAAAAAElFTkSuQmCC" alt="" />
一、 webView加载页面,重写shouldOverrideUrlLoading方法,不使用系统默认的浏览器:
private WebView webView;
private EditText editText;
private String htmlUrl = "file:///android_asset/index.html"; private void initComponent() {
webView = (WebView) findViewById(R.id.webView);
editText = (EditText) findViewById(R.id.editText);
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initComponent(); webView.getSettings().setJavaScriptEnabled(true); // 支持javascript
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url); // 根据传入的参数再去加载新的网页
return true; // 表示当前WebView可以处理打开新网页的请求,不用借助系统浏览器
}
});
}
二、 用webView加载url资源:
// 请求url资源:
public void searchURL(View view) {
String urlStr = editText.getText().toString();
webView.loadUrl(htmlUrl);
}
三、 用webView加载数据:
// 加载html代码片断
public void loadDataMethod(View view) {
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webView.loadData(summary, "text/html", "utf-8");
}
四、 我们还可心在请求的html资源中,加入带有andoroid支持的JS代码。例如在js中使用toast,首先我们定义一个类,供在js中调用:
public class AppUseJSInterface {
Context mContext; AppUseJSInterface(Context c) {
mContext = c;
} @JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_LONG).show();
}
}
接着我们在android代码中使用addJavascriptInterface方法,关联js与android:
// 请求html资源,在js中使用android
public void searchHTML(View view) {
// 给这个对象起的别名叫“huhxJS”
webView.addJavascriptInterface(new AppUseJSInterface(this), "huhxJS");
webView.loadUrl(htmlUrl);
}
最后我们在js中使用android定义的接口:
<script type="text/javascript">
function androidJS() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
huhxJS.showToast("username: " + username + ", password: " + password);
}
</script>
五、 我们还可以在andoird中调用js代码,如下:
在android调用js中的javascriptJS函数:
// 在android中调用js
public void useJSInAndroid(View view) {
String name = "I love you";
webView.loadUrl("javascript:javascriptJS('" + name + "')");
}
在js中定义javascriptJS()函数:
function javascriptJS(some) {
huhxJS.showToast(some);
}
六、 实现webView的回退功能:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
} else if (keyCode == KeyEvent.KEYCODE_FORWARD && webView.canGoForward()) {
webView.goForward();
return true;
}
return super.onKeyDown(keyCode, event);
}
七、 测试加载用的页面:index.html
<html>
<head>
<script type="text/javascript">
function androidJS() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
huhxJS.showToast("username: " + username + ", password: " + password);
}
function javascriptJS(some) {
huhxJS.showToast(some);
}
</script>
</head>
<body>
<form action="#" method="get">
<font color="red">username:</font> <input type="text" id="username" name="username"><br>
<font color="red">password:</font> <input type="password" id="password" name="password"><br>
<input type="submit" value="submit">
</form>
<Button onclick="androidJS()">ClickOnMe</Button>
</body>
</html>
友情链接
android基础---->WebView的使用的更多相关文章
- Android中webView的基础使用(一)
WebView是View的一个子类,可以让你在activity中显示网页. 可以在布局文件中写入WebView:比如下面这个写了一个填满整个屏幕的WebView: <?xml version=& ...
- Android之webview详解
文章大纲 一.webview基本介绍1.什么是webview2.为什么要使用webview3.webview基本操作 二.webview高级使用1.WebView状态2.资源加载3.WebView加载 ...
- Android Chromium WebView学习启动篇
Android从4.4起提供基于Chromium实现的WebView.此前WebView基于WebKit实现.WebKit提供网页解析.布局和绘制以及JS执行等基础功能.Chromium在WebKit ...
- android 之WebView
(一)使用中遇到的问题: 1.解决webview缓存: WebSettings.LOAD_NO_CACHE 或者直接清除缓存 webView.getSettings().setCatchMode( ...
- Android中webView和网页的交互
Android中webView和网页的交互 Android中webView跟网页的交互式通过JavaScript进行的.具体步骤: 1.创建JavaScript,在点击的时候调用JavaScript ...
- Android基础测试题(四)
看了前两道题大家有没有发现,测试题少了(一),大家猜猜测试题(一)是什么? Android基础测试题(四): 需求: 建一个方法,格式化输出2016-11-14 10:15:26格式的当前时间,然后截 ...
- Android基础测试题(二)
今天给大家带来的是Android基础测试题(二) 题目要求: 定义一个5位长度的整型数组并初始化,然后构建方法根据用户传入的数字判断是否存在数组中,如果存在,返回所在位置,如果不存在,返回-1 首先第 ...
- Mono.Android 基础
Mono.Android 基础 (地址) Mono.Android项目结构是 — Project + Assets + Resources + drawable + layout + values R ...
- Android 显示 WebView ,加载URL 时,向webview的 header 里面传递参数
1.主要布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:and ...
随机推荐
- python 中的tile函数,shape函数,sum函数
1.tile函数: tile函数是模板numpy.lib.shape_base中的函数.函数的形式是tile(A,reps) A的类型几乎所有类型都可以:array, list, tuple, dic ...
- Java线程池(ExecutorService)使用
一.前提 /** * 线程运行demo,运行时打出线程id以及传入线程中参数 */ public class ThreadRunner implements Runnable { private fi ...
- java项目部署到LIINUX
天领导给个任务,把java项目部署到liunx服务器上.现记录步骤,方便以后查看.项目部署服务器步骤:服务器信息:弹性IP地址:xx.xx.xxx.xx账号:root密码:cjw@100 数据库信息: ...
- 题解 UVa11609
题目大意 给定一个正整数 \(n\),请求出所有小于 \(n\) 人的团队如果选出一个人作为队长的不同的方案数(假定这些人两两不相同)对 \(10^9+7\)取模的结果. 分析 即求 \[\sum^n ...
- (2)ESP8266 矩阵的逆求解
#include "math.h" int N=4; int M=4; float a[4][4]={ {1,0,0,0}, {1,0.5,0,0}, {1,0,1,0}, {1, ...
- 洛谷 P1908 逆序对 题解
每日一题 day43 打卡 Analysis 因为数据规模,所以我们需要对其进行离散化,新创一个数组a里面来放在我们的初始序列中在这个位置上的数是第几大的这里还要用一个小技巧排序,关于离散化的技巧我们 ...
- 关于redash 自定义可视化以及query runner 开发的几篇文章
以下是几篇关于如如何编码redash 自定义可视化插件以及query runner 的连接,很有借鉴价值 参考连接 https://discuss.redash.io/t/how-to-create- ...
- PDO和MySQLi区别和数度;到底用哪个?
当用PHP访问数据库时,除了PHP自带的数据库驱动,我们一般还有两种比较好的选择:PDO和MySQLi.在实际开发过程中要决定选择哪一种首先要对二者有一个比较全面的了解.本文就针对他们的不同点进行分析 ...
- JMeter学习1
Jmeter的组织方式相对比较扁平,直接是TestPlan(相当于Project),TestPlan下创建的ThreadsGroup(相当于TestCase), Jmeter一个TestPlan也是一 ...
- something about 乘法逆元
before 在求解除法取模问题(a / b) % m时,我们可以转化为(a % (b * m)) / b, 但是如果b很大,则会出现爆精度问题,所以我们避免使用除法直接计算. (逆元就像是倒数一样的 ...