I'm using BottomNavigationView for managing fragments. Is there a simple solution for change tab item font ? I used SpannableStringBuilder . But it's not working.
for (int i = 0; i < bottomBar.getMenu().size(); i++) {
MenuItem menuItem = binding.bottomBar.getMenu().getItem(i);
SpannableStringBuilder title = new SpannableStringBuilder(menuItem.getTitle());
title.setSpan(mTypeface, 0, title.length(), 0);
menuItem.setTitle(title);
}
Finally I found solution. First I found CustonTypefaceSpan class. CustomTypefaceSpan extended from TypefaceSpan class. You can check this answer.
CustomTypefaceSpan typefaceSpan = new CustomTypefaceSpan("", mTypeface);
for (int i = 0; i <bottomBar.getMenu().size(); i++) {
MenuItem menuItem = bottomBar.getMenu().getItem(i);
SpannableStringBuilder spannableTitle = new SpannableStringBuilder(menuItem.getTitle());
spannableTitle.setSpan(typefaceSpan, 0, spannableTitle.length(), 0);
menuItem.setTitle(spannableTitle);
}
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