Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
        }
like image 974
yusufonderd Avatar asked Jul 17 '17 12:07

yusufonderd


1 Answers

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);
        }
like image 164
yusufonderd Avatar answered Sep 29 '22 22:09

yusufonderd