Android - How to change bottom navigation bar text's font family
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 have a CustomFont in "Asset Folder" and you want to set in your "Bottom Navigation" use this code
public static void persian_iran_font(final Context context, final View v) { try { if (v instanceof ViewGroup) { ViewGroup vg = (ViewGroup) v; for (int i = 0; i < vg.getChildCount(); i++) { View child = vg.getChildAt(i); persian_iran_font(context, child); } } else if (v instanceof TextView) { ((TextView) v).setTypeface(Typeface.createFromAsset(context.getAssets(), "teshrinarmedium.otf")); } } catch (Exception e) { } }
And then use methode in your MainActivityLike This
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); persian_iran_font(getApplicationContext(), navigation);
kotlin Version
fun persian_iran_font(context: Context, v: View) { try { if (v is ViewGroup) { val vg = v as ViewGroup for (i in 0 until vg.childCount) { val child: View = vg.getChildAt(i) persian_iran_font(context, child) } } else if (v is TextView) { (v as TextView).setTypeface( Typeface.createFromAsset( context.getAssets(), "teshrinarmedium.otf" ) ) } } catch (e: Exception) { }}
Goodluck