QuickContackBadge继承了ImageView,因此它的本质也是图片,也可以通过android:src属性指定它显示的图片。
QuickContackBadge额外功能是:该图片可以关联到手机中指定联系人,当用户单击该图片时,系统会打开相应联系人的联系方式界面。
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_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/ic_launcher"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
android:text="电话号码"/>
</LinearLayout>
java程序:
public class MainActivity extends Activity {
QuickContactBadge badge;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取QuickContactBadge组件
badge = (QuickContactBadge) findViewById(R.id.badge);
// 将QuickContactBadge组件与特定电话号码对应的联系人建立关联
badge.assignContactFromPhone("020-88888888", false);
}
}
显示效果: