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的點擊事件綁定!

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM