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 c
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 MainActivity Like 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