안드로이드
(Android) Roboto 폰트 적용
danune.dev
2022. 6. 10. 00:14
구글에서 개발한 Roboto 폰트를 적용하는 방법입니다 (영문 한정)
Roboto 폰트에 대한자세한 내용은 아래 링크를 참고하세요
https://fonts.google.com/specimen/Roboto
Google Fonts
Making the web more beautiful, fast, and open through great typography
fonts.google.com
fontFamily를 sans-serif로 변경 시 영문은 자동으로 Roboto font가 사용됩니다
Roboto는 구글에서 개발한 가독성 좋은 폰트로, 위 예제에서 보는 것 처럼 100~900까지 모든 text weight를 표현할 수 있어서 다양한 디자인을 표현할 수 있습니다
한글은 아쉽게도 전체 font weight 가 구현되어있지 않아, 일부 font weight구간이 동일하게 표현됩니다
- 100~300
- 400
- 500~600
- 700~800
- 900
1. 앱 전체에 폰트 적용
sans-serif(roboto)는 기본 탑재되어있는 폰트라 별도로 폰트파일을 추가하지 않고 사용할 수 있습니다
themes 파일에서 font-family를 sans-serif 로변경하는것으로 앱 전체에 폰트를 적용할 수 있습니다
<item name="android:fontFamily">sans-serif</item>
2. 개별 폰트 적용
만약 일부 UI에서만 폰트를 적용하고자 한다면 fontFamily 속성을 설정하면 됩니다
<TextView
style="@style/TextLarge"
android:layout_height="wrap_content"
android:padding="@dimen/margin_large"
android:textFontWeight="900"
android:fontFamily="sans-serif"
android:text="sans-serif, 한글, fontWeight 900" />