软件编程
位置:首页>> 软件编程>> Android编程>> Android给TextView添加点击事件的实现方法

Android给TextView添加点击事件的实现方法

作者:jingxian  发布时间:2023-08-08 13:59:49 

标签: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(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的点击事件绑定!

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com