【android实用工具 一】 自定义拨打电话界面
来源:互联网 发布:c指针编程之道 pdf 编辑:程序博客网 时间:2024/04/29 06:21
相信大家在项目中或多或少都会用到拨打电话的功能,其实可以直接用Intent方法去调用系统的拨打电话功能,很简单的(如果不知道 下面的代码会体现到)我这里做了一个自定义的拨打电话界面,非常方便,如果您的项目需要此功能不妨试试还算比较灵活
上代码
package com.empolder.sample.utils;import android.app.AlertDialog;import android.content.Context;import android.content.Intent;import android.graphics.Color;import android.net.Uri;import android.view.View;import android.widget.Button;import android.widget.TextView;import com.empolder.sample.R;/** * @author Michael * @描述 拨打电话 */public class CallPhone { private TextView phone_desc; // 取消拨打电话 private Button btnCancelCall; // 打电话 private Button btnCall; private AlertDialog dialog; private String tel; // 这里用到单利模式 private static CallPhone call = new CallPhone(); // 构造函数私有化 private CallPhone() { } // 创建本类的静态对象 public static CallPhone getInstance() { return call; } /** * 拨打电话 * * @param context 上下文对象 * @param telephone 电话号码 * @param parseColor 例 "#FFFFFF" */ public void callPhone(final Context context, final String telephone, String parseColor) { AlertDialog.Builder builder = new AlertDialog.Builder(context); View view = View.inflate(context, R.layout.custom_dialog_call_phone, null); phone_desc = (TextView) view.findViewById(R.id.phone_desc); phone_desc.setText("确定要拨打 " + telephone + " 吗?"); phone_desc.setTextColor(Color.parseColor(parseColor)); btnCall = (Button) view.findViewById(R.id.btnCall); btnCall.setTextColor(Color.parseColor(parseColor)); btnCall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tel = telephone.replaceAll("-", ""); Intent intent = new Intent(); intent.setAction(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + tel)); context.startActivity(intent); dialog.dismiss(); } }); btnCancelCall = (Button) view.findViewById(R.id.btnCancelCall); btnCancelCall.setTextColor(Color.parseColor(parseColor)); btnCancelCall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setView(view, 0, 0, 0, 0); dialog.show(); }}
xml文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/margin_twenty" android:background="@color/white_translucent" android:orientation="vertical" android:padding="@dimen/margin_ten" > <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/margin_one_hundred_fifty" android:orientation="vertical" > <TextView android:id="@+id/phone_desc" android:layout_width="wrap_content" android:layout_height="44dp" android:layout_centerHorizontal="true" android:layout_gravity="center" android:layout_marginTop="@dimen/margin_ten" android:gravity="center" android:text="@string/sure_call_phone" android:textColor="@color/main_actionbar" android:textSize="@dimen/text_size_eighteen" android:textStyle="bold" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="@dimen/margin_ten" android:layout_marginTop="@dimen/margin_ten" > <Button android:id="@+id/btnCall" android:layout_width="@dimen/margin_zero" android:layout_height="@dimen/public_high" android:layout_marginRight="@dimen/margin_five" android:layout_weight="1" android:background="@null" android:text="@string/call_phone_call" android:textColor="@color/main_actionbar" android:textSize="@dimen/text_size_sixteen" /> <Button android:id="@+id/btnCancelCall" android:layout_width="@dimen/margin_zero" android:layout_height="@dimen/public_high" android:layout_marginLeft="@dimen/margin_five" android:layout_weight="1" android:background="@null" android:text="@string/call_phone_cancel" android:textColor="@color/main_actionbar" android:textSize="@dimen/text_size_sixteen" /> </LinearLayout> </RelativeLayout></LinearLayout>
这里说明一下,我一般写的方便调用的类库都会选择单利模式,如果不知道单利模式可以看看我之前写的博客,或者百度一下 很多。
使用
CallPhone callPhone = CallPhone.getInstance(); callPhone.callPhone(getApplicationContext(),"110","#676767");
很简单吧 直接创建对象 传入上下文对象,传入你要拨打的电话号码,传入你要的文字颜色即可,好本文到此!
阅读全文
0 0
- 【android实用工具 一】 自定义拨打电话界面
- Android调用拨打电话界面
- Android 拨打电话以及跳转到拨打电话界面
- Android跳转到拨打电话界面
- Android调用拨号界面、拨打电话功能
- Android调用拨号界面、拨打电话功能
- Android调用拨号界面、拨打电话功能
- web界面拨打电话
- Android开发(一)拨打电话程序
- Android开发(一)拨打电话程序
- Android开发(一)拨打电话程序
- Android开发(一)拨打电话程序
- (小笔记) android 直接拨打电话和进入拨打电话界面
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Android弹出拨号界面和拨打电话实现
- Apache原理详解
- 移动端简介(1)
- 第十篇:使用wait/notify/notifyAll实现线程间通信的几点重要说明
- 51 nod 1277 字符串中的最大值(KMP)
- oracle常用笔记
- 【android实用工具 一】 自定义拨打电话界面
- 弗布克官网总结
- ARCGIS下一个面把另一个面切成两半
- Linux命令大全
- Nginx原理详解
- EL表达式
- Uva 12125 March of the Penguins(最大流)
- Windows Server 2012 R2 没有我的电脑解决方法
- fzu-2253