QuickContactBadge 继承了 ImageView 因此它的本质也是图片按钮,也可以通过 android:src 属性指定它显示的图片。QuickContactBadge 额外增加的功能是:该图片可以关联到手机中指定联系人,当用户单机该图片的时候,系统将会打开相应联系人的联系方式界面。
QuickContactBadge 需要调用的方法
- assignContactFromEmail(String emailAddapp\src\main\ress,boolean lazyLookup):将该图片关联到指定 E-mail 地址对应的联系人
- assignContactFromPhone(String phoneNumber,boolean lazyLookup):将该图片关联到指定电话号码对应的联系人
- assignContactUri(Uri contactUri) 将该图片关联到特定 Uri 对应的联系人
本案例效果图如下
布局文件代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="pub.weber.bym.quickcontactbadge.MainActivity">
<QuickContactBadge
android:id="@+id/badge"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/c"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
android:text="weber开发者"/>
</LinearLayout>
MainActivity 代码如下
public class MainActivity extends AppCompatActivity {
QuickContactBadge badge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
badge = (QuickContactBadge) findViewById(R.id.badge);
badge.assignContactFromPhone("110-12345678",false);
}
}