Android给TextView添加点击事件

2025-04-22 12:46:22

1、首先设定TextView的clickable属性为true。可以在布局文件中进行设定,比如:<TextView andro足毂忍珩id: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);

2、然后绑定事件回调函数: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); } });

3、完成TextView的点击事件绑定!

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢