您的位置:首页 > 移动开发 > Android开发

android自定义标签!(实现打电话的功能);

2014-10-20 10:17 459 查看

在使用webview这一方面;自定义标签是很重要的一个技术;最近项目我也使用到了自定义标签;在此分享代码如下;

作为程序员学会分析也是很重要的;

分享代码前先来分析分析哈;

android自定义标签需要使用到的类有webviewClient这个类;我们要做的是重写这里面的一个方法;这个重写的方法里有一个参数是url;我们就要用到url;

我在这里需要用到有activity;layout;html文件;在javascript调用android打电话;还需要添加打电话权限哦;

layout文件主要就是一个webview控件;在此就不写了哈;

java代码;如下;

package com.tarena.chat.view;

import com.tarena.chat.R;

import android.app.Activity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.webkit.WebView;

import android.webkit.WebViewClient;

public class HelpActivity extends Activity{

private WebView webview;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.help_layout);

webview=(WebView)findViewById(R.id.gridView1);

webview.loadUrl("file:///android_asset/help.html");

webview=new WebView(getApplicationContext());

webview.setWebViewClient(new WebViewClient(){

@Override

public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (url.contains("tarena/tell:")) {

String index="tarena/tell:";

String phone=url.substring(index.indexOf("tarena/tell".length()));

Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tell"+phone));

startActivity(intent);

}

return super.shouldOverrideUrlLoading(view, url);

}

});

}

}

html文件如下;我在这里是将html文件放到了asset目录下;

<html>

<head>

<body>

<p>欢迎使用天天聊天软件</p>

<p>这个软件使用很方便</p>

<p>这个软件使用很方便</p>

<p>这个软件使用很方便</p>

<p>这个软件使用很方便</p>

<p>这个软件使用很方便</p>

<p>这个软件使用很方便</p>

<a href="tarena/tell:13265562350">联系我们</a>

<a href="http://blog.csdn.net/android_drawing">访问官方博客</a>

</body>

</head>

</html>

ok啦;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: