sorunluadam sorunluadam - 3 years ago 227
Android Question

BottomNavigationView - How to change menu item font?

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);
}

Answer Source

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);
        }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download