Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.support.design.widget.BottomNavigationView             android:layout_width="match_parent"             android:layout_height="match_parent"             android:id="@+id/bottomNavView_Bar"             android:background="@drawable/white_grey_border_top"             app:menu="@menu/bottom_navigation_menu"> </android.support.design.widget.BottomNavigationView> 

Also, code in bottom_navigation_menu.xml:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"       >      <item         android:id="@+id/ic_newsfeed"         android:icon="@drawable/ic_menu_camera"         android:title="NEWSFEED"         />          <item             android:id="@+id/ic_explorer"             android:icon="@drawable/ic_home_black_24dp"             android:title="EXPLORER"             />         <item             android:id="@+id/ic_notify"             android:icon="@drawable/ic_notifications_black_24dp"             android:title="NOTIFY"             />         <item             android:id="@+id/ic_more"             android:icon="@drawable/ic_dashboard_black_24dp"             android:title="MORE"             />  </menu> 

Help would be appreciated.

Thanks in advance!

like image 223
Neha Beniwal Avatar asked Aug 10 '17 05:08

Neha Beniwal


People also ask

How do I change the bottom navigation bar style in Android?

There are two ways to style the navigation bar depends on how you create it. One is using the XML style file if you create the navigation bar from XML. The other one is to change it using code.

How do I code the bottom navigation bar for an Android app?

To create a Menu Resource File , click on the app -> res -> menu(right-click) -> New -> Menu Resource File and name it bottom_nav_menu. Now the user can create as many items as he wants in the bottom_nav_menu. xml file. The user also needs to create an icon for each of these items.


2 Answers

add the font file in the res/font/ folder to bundle fonts as resources

then

You can change it using style resources. In your styles.xml:

<style name="Widget.BottomNavigationView"      parent="Widget.Design.BottomNavigationView">     <item name="fontFamily">@font/your_font</item> </style> 

Then apply it as a theme in your view:

<android.support.design.widget.BottomNavigationView     ...     android:theme="@style/Widget.BottomNavigationView" /> 

Just checked on my app, it works fine.

reference: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html#fonts-in-code

like image 127
A. Kazarovets Avatar answered Sep 23 '22 14:09

A. Kazarovets


In your layout:

<com.google.android.material.bottomnavigation.BottomNavigationView     ...     app:itemTextAppearanceActive="@style/BottomNavigationViewTextStyle"     app:itemTextAppearanceInactive="@style/BottomNavigationViewTextStyle"     ... /> 

In your styles.xml:

<style name="BottomNavigationViewTextStyle">     ...     <item name="android:fontFamily">@font/whatever_font</item>     ... </style> 
like image 20
janosch Avatar answered Sep 22 '22 14:09

janosch