android学习笔记——使用QuickContactBadge关联联系人
本文大部分内容来自《疯狂android讲义》.
QuickContactBadge继承了ImageView,因此它的本质也是图片,也可以通过android:src属性指定它显示的图片。QuickcontactBadge额外增加的功能是:该图片可以关联到手机中指定联系人,当用户单击该图片时,系统将会打开相应联系人的联系方式界面。
为了让QuickContactBadge与特定联系人关联,可以调用如下方法进行关联。
assignContactFromEmail(String emailAddress,boolean lazyLookup):将该图片关联到指定E-mail 地址对应的联系人。
assignContactFromPhone(String phoneNumber,boolean lazyLookup):将该图片关联到指定电话号码对应的联系人。
assignContactFromUri(Uri contactUri):将该图片关联到特定Uri对应的联系人。
main.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="match_parent" > <QuickContactBadge android:id="@+id/badge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="16dp" android:text="我的偶像" /> </LinearLayout>
MyActivity.java
package com.example.test3_3_6; import android.app.Activity; import android.os.Bundle; import android.widget.QuickContactBadge; public class MyActivity extends Activity { /** * Called when the activity is first created. */ QuickContactBadge badge; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 获取QuickContactBadge组件 badge=(QuickContactBadge)findViewById(R.id.badge); // 将QuickContactBadge组件与特定电话号码对应的联系人建立联系 badge.assignContactFromPhone("020-88888888",false); } }