QuickContactBadge的用法

来源:互联网 发布:the python challenge 编辑:程序博客网 时间:2024/06/06 02:58

以前看到人家程序里面的点击某个头像出现类似PopWindow的UI,觉得非常的酷,今天看系统SMS的源代码,发现原来是系统已经提供的控件,QuickContactBadge!汗!


先看看QuickContactBadge如何使用:

 

其他它的使用是非常简单的,和系统其他的控件的使用是一样一样滴。如api demo里面的:


<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:paddingLeft="0dip"
    android:paddingRight="9dip"
    android:layout_height= "wrap_content"
    android:minHeight="48dip">

    <QuickContactBadge
        android:id="@+id/badge"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="14dip"
        android:layout_marginTop="4dip"
        android:layout_marginBottom="3dip"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_height= "wrap_content"
        android:layout_width= "wrap_content"
        android:src="@drawable/ic_contact_picture"
        style="?android:attr/quickContactBadgeStyleWindowSmall" />

    <TextView
        android:id="@+id/name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:paddingLeft="2dip"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/badge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

然后呢,你只需要给他绑定你联系人的uri就行了,但是注意如果有的号码没有uri如何解决?

 

 assignContactUri(Uri contactUri)或者

assignContactFromPhone(String phoneNumber, boolean lazyLookup)

即可。


多看开源代码哇!