參考《瘋狂Android講義》
api 地址:https://developer.android.com/reference/android/widget/QuickContactBadge?hl=en
QuickContactBadge繼承了ImageView捧颅,因此它的本質(zhì)也是圖片撩独,也可以通過android:src屬性指定它顯示的圖片。QuickcontactBadge額外增加的功能是:該圖片可以關(guān)聯(lián)到手機(jī)中指定聯(lián)系人赋续,當(dāng)用戶單擊該圖片時,系統(tǒng)將會打開相應(yīng)聯(lián)系人的聯(lián)系方式界面。
為了讓QuickContactBadge與特定聯(lián)系人關(guān)聯(lián),可以調(diào)用如下方法進(jìn)行關(guān)聯(lián)。
assignContactFromEmail(String emailAddress,boolean lazyLookup):將該圖片關(guān)聯(lián)到指定E-mail 地址對應(yīng)的聯(lián)系人树枫。
assignContactFromPhone(String phoneNumber,boolean lazyLookup):將該圖片關(guān)聯(lián)到指定電話號碼對應(yīng)的聯(lián)系人。
assignContactFromUri(Uri contactUri):將該圖片關(guān)聯(lián)到特定Uri對應(yīng)的聯(lián)系人景东。
<?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組件與特定電話號碼對應(yīng)的聯(lián)系人建立聯(lián)系
badge.assignContactFromPhone("020-88888888",false);