webView简单使用:网页中有电话,在客户端点击打电话(一)

一:
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>
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值