Notice
Recent Posts
Link
Today
Total
10-06 00:17
๊ด€๋ฆฌ ๋ฉ”๋‰ด

dingdong coding

[ Android / Kotlin ] Font Style ๋ณ€๊ฒฝ ๋ณธ๋ฌธ

๐ŸŒƒAndroid/Style

[ Android / Kotlin ] Font Style ๋ณ€๊ฒฝ

๐Ÿถ ๊ฐœ๋ฐœ๊ฐœ๋ฐœ ๐Ÿพ 2022. 1. 9. 16:38

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>

 

์ด์ œ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ํฐํŠธ๋ฅผ ๋‹ค์šด๋ฐ›์œผ๋Ÿฌ ๊ฐ€๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

 

https://fonts.google.com/

 

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 : ๋ถ€์กฑํ•œ ๋ถ€๋ถ„์€ ๊ณ„์†ํ•ด์„œ ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿฅฐ

Comments