Android给TextView添加点击事件的实现方法
作者:jingxian 时间:2023-08-08 13:59:49
首先设定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的点击事件绑定!
标签:textview,添加,点击事件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解spring-boot actuator(监控)配置和使用
2022-07-12 17:20:37
Jackson多态序列化图文详解
2022-01-26 19:46:08
![](https://img.aspxhome.com/file/2023/1/69891_0s.jpg)
IntelliJ IDEA中显示和关闭工具栏与目录栏的方法
2023-09-01 23:18:59
![](https://img.aspxhome.com/file/2023/9/93079_0s.png)
java导出csv格式文件的方法
2022-07-24 20:26:36
![](https://img.aspxhome.com/file/2023/5/62665_0s.jpg)
MyBatis找不到mapper文件的实现
2023-12-15 09:22:11
![](https://img.aspxhome.com/file/2023/1/61131_0s.png)
C#判断字符是否为汉字的三种方法分享
2022-05-24 07:59:41
详解idea从git上拉取maven项目详细步骤
2023-04-23 08:51:56
![](https://img.aspxhome.com/file/2023/5/83115_0s.png)
Java中常用的设计模式之观察者模式详解
2023-07-27 12:32:52
![](https://img.aspxhome.com/file/2023/0/75450_0s.png)
Java中List Set和Map之间的区别_动力节点Java学院整理
2022-12-11 04:57:38
ShardingSphere jdbc实现分库分表核心概念详解
2023-11-24 12:09:45
![](https://img.aspxhome.com/file/2023/3/59763_0s.png)
Android利用SAX对XML进行增删改查操作详解
2023-02-05 00:03:32
Java反射获取实例的速度对比分析
2021-06-14 09:22:29
java 中ArrayList与LinkedList性能比较
2023-03-28 05:45:43
Java判断线程池线程是否执行完毕
2023-10-18 12:09:29
JavaWeb使用POI操作Excel文件实例
2022-06-12 18:19:30
![](https://img.aspxhome.com/file/2023/5/72385_0s.png)
Android实现网易云音乐高仿版流程
2023-05-13 22:08:50
![](https://img.aspxhome.com/file/2023/2/92622_0s.png)
C++初阶教程之类和对象
2021-07-24 18:53:46
![](https://img.aspxhome.com/file/2023/8/120818_0s.png)
Java异常处理之try...catch...语句的使用进阶
2022-03-16 03:06:09
Android 开发中Volley详解及实例
2023-07-21 00:12:19
Java面向对象之猜拳游戏
2022-10-29 21:26:45
![](https://img.aspxhome.com/file/2023/8/80208_0s.jpg)