[ Android / Kotlin ] Font Style ๋ณ๊ฒฝ
Android ๊ฐ๋ฐ ์ ์ํ๋ Font๋ฅผ ๋ค์ด๋ฐ์ ์ฌ์ฉํ๋ ๋ฒ์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค.
๋จผ์ res ํด๋์ font style์ ์ง์ ํ ํด๋๋ฅผ ํ๋ ์์ฑํฉ๋๋ค.
res ์ฐํด๋ฆญ > New > Android Resource Directory
Resource type > font ์ ํ
์ดํ font > font_style.xml ์ ์์ฑํฉ๋๋ค.
font_style.xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:font="@font/๋ค์ด๋ฐ์ font file name" />
<font
android:fontStyle="italic"
android:font="@font/๋ค์ด๋ฐ์ font file name" />
</font-family>
์ด์ ์ฌ์ฉํ๊ณ ์ ํ๋ ํฐํธ๋ฅผ ๋ค์ด๋ฐ์ผ๋ฌ ๊ฐ๋ณด๊ฒ ์ต๋๋ค.
Google Fonts
Making the web more beautiful, fast, and open through great typography
fonts.google.com
์ฌ์ฉํ๊ณ ์ ํ๋ font style์ ๊ฒฐ์ ํ๋ค๋ฉด
style์ ์ดํด๋ณธ ํ Download all ์ ๋๋ฌ ํฐํธ๋ฅผ ๋ค์ด ๋ฐ์ต๋๋ค.
๋ค์ด์ ๋ฐ์ ํ ์์ถ์ ํ์ด์ฃผ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ttf ํ์ผ๋ค์ด ์์ต๋๋ค.
์ด ์ค ๋ด๊ฐ ์ฌ์ฉํ๊ณ ์ถ์ ํฐํธ๋ฅผ ๊ณ ๋ฆ ๋๋ค.
ํฐํธ๋ฅผ ๊ณ ๋ฅธ ํ res ํด๋ ํ๋จ์ ์์ฑํ fontํด๋์ ๋ค์๊ณผ ๊ฐ์ด Ctrl+c -> Ctrl+v , ๋ณต์ฌ -> ๋ถ์ฌ๋ฃ๊ธฐ ๋ฅผ ํด์ค๋๋ค.
์ด์ ๋ค์ font_style.xml ๋ก ๋์์ ๋ด๊ฐ ์ฌ์ฉํ๊ณ ์ถ์ font์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ง์ ํด์ค๋๋ค.
font_style.xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:font="@font/opensans_semibold" />
<font
android:fontStyle="italic"
android:font="@font/lobster_italic" />
</font-family>
์ด์ ์ฌ์ฉํ๊ณ ์ถ์ font style์ ๊ฐ์ ธ์ค๋ ์์ ์ ๋ง๋ฌด๋ฆฌ ๋์ต๋๋ค.
์ฌ์ฉ๋ฒ์ ๋ํด ์์๋ณด๊ฒ ์ต๋๋ค.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Calendar"
android:textColor="#464646"
android:gravity="left|center_vertical"
android:fontFamily="@font/font_style" // ์ด ๋ถ๋ถ!
android:textSize="40sp"/>
font๋ฅผ ์ง์ ํ๊ณ ์ถ์ TextView์ fontFamily์ font_style.xml ์ ๋ถ๋ฌ์์ ์ฌ์ฉํ๋ฉด ๋ !
์ด์ font style ๋ณ๊ฒฝ์ ๋ํด ์์๋ดค์ต๋๋ค.
P.S : ๋ถ์กฑํ ๋ถ๋ถ์ ๊ณ์ํด์ ์์ ํ๊ฒ ์ต๋๋ค. ๐ฅฐ