본문 바로가기
프로젝트 기록/android

[android/안드로이드] link걸기

by 새아SaeA 2019. 12. 29.

android link걸기 예제

 

/res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">
    
    <TextView
    	android:id="@+id/webText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="https://saeatechnote.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-link%EA%B1%B8%EA%B8%B0?category=850025"
        android:autoLink="web|email"
        android:linksClickable="true"
        />
    <TextView
    	android:id="@+id/emailText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="saeatechnote@tistory.com"
        android:autoLink="web|email"
        android:linksClickable="true"
        />
    <TextView
    	android:id="@+id/phoneText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="01012345678"
        android:autoLink="phone|map"
        android:linksClickable="true"
        />
    <TextView
    	android:id="@+id/mapText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2151 Martin Luther King Jr Way, Berkeley, CA 94704"
        android:autoLink="phone|map"
        android:linksClickable="true"
        />
    
</LinearLayout>

//자바 파일은 따로 안해도 됨.

 

autoLink : TextView의 속성중 하나로 자동으로 링크가 걸린다.

autoLink="none"

- 아무것에도 링크를 걸지 않는다.

autoLink="all"

- 해당되는 것이면 다 링크된다.

autoLink="web|email"

- text에 웹 주소나 이메일을 입력하면 자동으로 링크가 걸려서 해당 웹으로 이동하거나 이메일을 보낼 수 있다.

autoLink="phone|map"

- text에 전화번호나 주소를 입력하면 자동으로 링크라 걸려서 해당 번호로 전화 앱이 실행되거나, 지도앱이 실행된다.