参考《疯狂Android讲义》
api 地址:https://developer.android.com/reference/android/widget/QuickContactBadge?hl=en
QuickContactBadge继承了ImageView,因此它的本质也是图片,也可以通过android:src属性指定它显示的图片。QuickcontactBadge额外增加的功能是:该图片可以关联到手机中指定联系人,当用户单击该图片时,系统将会打开相应联系人的联系方式界面。
为了让QuickContactBadge与特定联系人关联,可以调用如下方法进行关联。
assignContactFromEmail(String emailAddress,boolean lazyLookup):将该图片关联到指定E-mail 地址对应的联系人。
assignContactFromPhone(String phoneNumber,boolean lazyLookup):将该图片关联到指定电话号码对应的联系人。
assignContactFromUri(Uri contactUri):将该图片关联到特定Uri对应的联系人。
<?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"
android:orientation="horizontal">
<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>
onCreate()
// 获取QuickContactBadge组件
badge=(QuickContactBadge)findViewById(R.id.badge);
// 将QuickContactBadge组件与特定电话号码对应的联系人建立联系
badge.assignContactFromPhone("020-88888888",false);