[Android] TextView

강승구·2022년 5월 12일

TextView는 텍스트 출력 기능을 가진 기본 위젯으로 안드로이드 UI를 구성함에 있어 화면에 텍스트를 표시하는 기능을 담당한다.

사용법

Layout xml 파일에 추가

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text1"
        android:text="Text1" />
</RelativeLayout>

글자 크기 설정

android:textSize="10sp"

행간 설정

android:lineSpacingExtra=”20dp”

글자 스타일 설정

android:textStyle="bold" //볼드체
android:textStyle="italic" //이텔릭체

글자 색상 설정

android:textColor="#FF0000"
 android:autoLink="all"
  • email : TextView의 text가 이메일 형식이면 클릭 시 이메일 앱을 열어줌
  • map : TextView의 text가 주소 형식이면 클릭 시 지도 앱을 열어줌
  • phone : TextView의 text가 전화번호 형식이면 클릭 시 전화 앱을 열어줌
  • web : TextView의 text가 전화번호 형식이면 클릭 시 인터넷 앱을 열어줌
  • all : TextVIew의 text가 위 4가지 중 하나면 클릭 시 해당하는 앱을 열어줌

줄 개수 설정

android:maxLines="1"

TextView의 길이를 넘어가는 경우 text 표시 옵션

android:ellipsize="end"
  • end : 글자 마지막 부분에 ... 넣기
  • start : 글자 첫 부분에 ... 넣기
  • middle : 글자 중간에 ... 넣기
  • none : 원래대로 글자 잘림
  • marquee : 흐르는 효과 적용
profile
강승구

0개의 댓글