Android給TextView添加點擊事件的實現(xiàn)方法
首先設(shè)定TextView的clickable屬性為true。
可以在布局文件中進行設(shè)定,比如:
<TextView
android:id="@+id/phone"
android:clickable="true" --------->設(shè)定此屬性
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代碼中設(shè)定:
textView.setClickable(true);
然后綁定事件回調(diào)函數(shù):
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//調(diào)到撥號界面
Uri uri = Uri.parse("tel:18764563501");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent);
}
});
完成TextView的點擊事件綁定!
以上就是小編為大家?guī)淼腁ndroid給TextView添加點擊事件的實現(xiàn)方法全部內(nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
Android實現(xiàn)動態(tài)高斯模糊效果示例代碼
這篇文章主要介紹了Android快速實現(xiàn)動態(tài)模糊效果示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-01-01
Android 修改系統(tǒng)關(guān)機動畫的實現(xiàn)
這篇文章主要介紹了Android 修改系統(tǒng)關(guān)機動畫的實現(xiàn)的相關(guān)資料,需要的朋友可以參考下2016-10-10
Android項目開發(fā)常用工具類LightTaskUtils源碼介紹
LightTaskUtils是一個輕量級的線程管理工具,本文通過實例代碼給大家詳細介紹Android項目開發(fā)常用工具類LightTaskUtils的相關(guān)知識,感興趣的朋友一起看看吧2022-06-06
Android開發(fā)中匿名設(shè)備標識符OAID使用及初始化
這篇文章主要為大家介紹了Android開發(fā)中匿名設(shè)備標識符OAID使用及初始化,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04

