zoukankan      html  css  js  c++  java
  • 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(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的点击事件绑定!

     

  • 相关阅读:
    模板类 & 虚函数
    Page Color (页面着色)
    修改静态库
    ElementUI 时间选择器
    自定义export
    vue组件
    ElementUI 表格
    ElementUI 分页
    数组方法分类
    Vue过滤数组副本
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4540095.html
Copyright © 2011-2022 走看看