JY-Dev Tech Blog

안드로이드(Android) - font 적용시키기 본문

안드로이드/레이아웃

안드로이드(Android) - font 적용시키기

JY-Dev 2020. 10. 8. 11:15

[OverView]

오늘은 어플리케이션에 font를 적용하는 방법에 대해 알려드리겠습니다.

 

일단 res폴더에 새로 font라는 디렉토리를 만들어줍니다.

그 다음은 사용할 ttf 파일을 font폴더 안에다 넣어줍니다.

 

[XML] 방식

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:fontFamily="@font/font"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

이런식으로 fontFamily 안에서 불러오시면 됩니다.

 

[Code] 방식

val typeFace = ResourcesCompat.getFont(context,R.font.font)
tv.typeface = typeFace

이렇게 typeface를 선언해서 해줄수 있습니다.

Comments