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!
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.
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.
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With