BottomNavigation의 폰트를 변경하는 방법

1. XML 파일에서 BottomNavigationView 세부 설정 수정
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/purple_500"
app:itemIconTint="@drawable/selector"
-------------수정할 부분--------------------------------------------------------
app:itemTextAppearanceActive="@style/BottomNavigationViewTextStyle"
app:itemTextAppearanceInactive="@style/BottomNavigationViewTextStyle"
-------------------------------------------------------------------------------
app:itemTextColor="@drawable/selector"
app:labelVisibilityMode="labeled"
app:menu="@menu/menu" />
2. rest/values/styles.xml 수정
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="BottomNavigationViewTextStyle">
...
<item name="android:fontFamily">@font/nanumsquareroundeb</item>
...
</style>
</resources>
주의사항: 사용하기 위한 폰트는 미리 다운로드 후 설정해야 함.
res 디렉토리에 font 디렉토리 생성 후, ttf 파일 저장. 그리고 app_font.xml 파일에 설정 필요

<?xml version="1.0" encoding="utf-8"?>
<font-family
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
android:font="@font/nanumsquareroundeb"
android:fontStyle="normal"
android:fontWeight="1000"
app:font="@font/nanumsquareroundeb"
app:fontStyle="normal"
app:fontWeight="1000"
tools:targetApi="o" />
</font-family>
| 참고
Android - How to change bottom navigation bar text's font family
I have created a bottom bar navigation in my android page. But now I want to apply the custom font-family in bottom navigation texts. This is the bottom navigation code in .xml file: <android.
stackoverflow.com
'개인기록 > 개발공부' 카테고리의 다른 글
| [React] 설치 과정에서 AWS 인스턴스와 VS Code 연결 끊김 현상 (0) | 2022.10.12 |
|---|---|
| [안드로이드] Chip을 Java 파일에서 생성하는 방법 (0) | 2022.10.11 |
| [안드로이드] D/EGL_emulation: app_time_stats: 없애는 법 (0) | 2022.10.08 |
| npm vs npm (0) | 2022.10.07 |
| [안드로이드] runOnUiThread 메서드 (1) | 2022.10.06 |