首先設定TextView的clickable屬性為true。
可以在布局文件中進行設定,比如:
<TextView android:id="@+id/phone" android:clickable="true" --------->設定此屬性 android:layout_marginLeft="10dp" android:layout_below="@id/address" android:layout_toRightOf="@id/avatar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="18764563523" android:textColor="@color/white" />
也可以在java代碼中設定:
textView.setClickable(true);
然后綁定事件回調函數:
textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { //調到撥號界面 Uri uri = Uri.parse("tel:18764563501"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent); } });
完成TextView的點擊事件綁定!