首先設定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);
然后綁定事件回調函數(shù):
textView.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {//調到撥號界面Uri uri = Uri.parse("tel:18764563501"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent);}});完成TextView的點擊事件綁定!
以上就是小編為大家?guī)淼腁ndroid給TextView添加點擊事件的實現(xiàn)方法全部內容了,希望大家多多支持武林網(wǎng)~
新聞熱點
疑難解答