본문 바로가기

Android/TextView, autoLink

Android TextView autoLink example

TextView를 이용하여 화면에 출력한 URL, Email, 전화번호 등에 자동으로 링크를 설정하고 누르면 관련 프로그램이 실행되는 예 (web, email, phone, all 등의 값을 설정할 수 있음)

autolink.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="match_parent" android:autoLink="all" android:text="블로그\nhttp://micropilot.tistory.com\n전화\n010-5000-4000\n이메일\ncwisky@mail.com"/> </LinearLayout>


TestActivity.java

package com.example.androidapp; import android.app.Activity; import android.os.Bundle; import android.widget.*; public class TestActivity extends Activity { TextView tv; EditText et; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.autolink); } }