본문 바로가기
개발자 도전기

[안드로이드] BottomNavigation 폰트 변경 방법

by 개발하는아빠 2022. 10. 10.

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>

 

| 참고

https://stackoverflow.com/questions/45604944/android-how-to-change-bottom-navigation-bar-texts-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