webView简单使用:网页中有电话,在客户端点击打电话(一)
2016-05-23 01:19
435 查看
一:
layout 中的布局文件 activity_main.xml
二:在MainActivity 的代码
三:提前做好的要显示的网页
layout 中的布局文件 activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
二:在MainActivity 的代码
import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { //webView相当于浏览器 声明webView WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化webview 控件 webView=(WebView) findViewById(R.id.webView); //需要显示在移动客户端的网页地址 URL webView.loadUrl("http://172.00.00.212:8080/manager/myhtml/mall.html"); //不加,单击超连接,启动系统的浏览器,加了之后在我们自己的APP中显示网页。 webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading (WebView view, String url) { Log.i("用户单击超连接", url); //判断用户单击的是那个超连接 String tag="tada:tel"; if (url.contains(tag)) { String mobile=url.substring(url.lastIndexOf("/")+1); Uri uri=Uri.parse("tel:"+mobile); Intent intent=new Intent(Intent.ACTION_CALL,uri); startActivity(intent); //这个超连接,java已经处理了,webview不要处理了 return true; } return super.shouldOverrideUrlLoading(view, url); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
三:提前做好的要显示的网页
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <table bgcolor="greenyellow" border="0" width="100%" height="100"> <tr> <td colspan="3" align="center"> <h1>商城</h1></td> </tr> <tr> <td>首页</td> <td>商品</td> <td><a href="index.html">订单</a> </td> </tr> </table> <table bgcolor="gray" width="100%"> <tr> <td bgcolor="aqua" width="100"> <table> <tr> <td>分类1</td> </tr> <tr> <td>分类2</td> </tr> </table> </td> <td> <table> <tr> <td><img src="img/11.jpg" width="200"></td> </tr> <tr> <td><img src="img/12.jpg" width="200"></td> </tr> </table> </td> </tr> </table> <table bgcolor="greenyellow" width="100%" height="60"> <tr><a href="tada:tel/13698888">联系电话:一小时送货上门</a> <a href="tarena:writedb/1#java&2#anaroid">保存</a> </tr> </table> </body> </html>
相关文章推荐
- [读书笔记]Android IPC机制(一)
- Android基础之SQLite的使用
- android LRUCache解析
- Android笔记(十六)文件存储
- 兄台息怒,关于arguments,您的想法和大神是一样一样的----闲聊JS中的apply和call
- android 简单的网格布局 GridLayout
- 当你关闭朋友圈后,微信对你做了什么?
- kappa一致性检验
- 微信月活跃用户破7.6亿,即将赶上QQ
- flask添加权限的时候出现TypeError: ObjectId('') is not JSON
- 微信公众号——信息理解
- iOS简易版的 仿popviewcontroller 功能
- iOStableView 自动布局常见问题之页面滑动到最底时,下面多出44的距离!
- 怎样免费注册apple id
- Android 听筒 扬声器 切换
- Android每个activity背景铺满整个屏幕包括标题栏
- Android 倒计时
- 在appstore里面搜索android会出现哪些鬼?
- iOS 数据持久化之一属性类表
- ios数据之久化