안드로이드/코드
[안드로이드] TextView, EditText 폰트 변경 하기(font-family, fontStyle)
everyshare
2019. 11. 15. 12:12
반응형
1. font 폴더 생성
res 폴더 안에 font 폴더를 생성합니다.
2. 원하는 폰트 파일을 font 폴더에 넣고 fontstyle.xml 파일을 생성
3. fontstyle.xml 코드 작성
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/swagger"/>
</font-family>
android:fontStyle="normal"
normal = 기본 서체
italic = 옆으로 기울어진 서체
android:fontWeight="400"
폰트의 굵기
400이 기본값입니다.
400보다 작게 한다면 글씨체가 더 얇게 변하고 크게 설정한다면 굵게 나옵니다.
android:font="@font/swagger"
font 폴더에 넣어뒀던 폰트 파일의 경로를 입력해주면 됩니다.
확장자명은 쓰지 않아도 됩니다.
4. xml에서 fontFamily 적용
<TextView
android:fontFamily="@font/fontstyle"/>
font 폴더의 fontstyle.xml 경로를 지정해주면 해당 fontstyle이 적용됩니다.
반응형