Android给TextView添加点击事件的实现方法
首先设定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(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
//调到拨号界面
Uriuri=Uri.parse("tel:18764563501");
Intentintent=newIntent(Intent.ACTION_DIAL,uri);
startActivity(intent);
}
});
完成TextView的点击事件绑定!
以上就是小编为大家带来的Android给TextView添加点击事件的实现方法全部内容了,希望大家多多支持毛票票~
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短