Calligraphy icon indicating copy to clipboard operation
Calligraphy copied to clipboard

Font not getting applied to PopupMenus or the BottomNavigationView

Open AlejandroHCruz opened this issue 5 years ago • 5 comments

Hi, I'm currently experiencing an issue in which the font I've setup to be used everywhere in the app is not working for the PopupMenus or the BottomNavigationView.

I've also tried specifying the fontPath in the items.xml files but it didn't help.

Any ideas?

Thank you!

AlejandroHCruz avatar Nov 29 '19 12:11 AlejandroHCruz

I have the same issue, did you find a solution?

yallam08 avatar Jan 25 '20 00:01 yallam08

Hi @AlejandroHCruz, I found a solution for this: For fixing the popups font, I put the ViewPump initialization code in my BaseActivity's onCreate() so it applies to all my activities:

public abstract class BaseActivity extends AppCompatActivity {

    //.............

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // apply the default font
        ViewPump.init(ViewPump.builder()
                .addInterceptor(new CalligraphyInterceptor(
                        new CalligraphyConfig.Builder()
                                .setDefaultFontPath(getString(R.string.font_normal))
                                .setFontAttrId(R.attr.fontPath)
                                .build()))
                .build());

        super.onCreate(savedInstanceState);
    }

    //.............

}

And for applying the font on BottomNavigationView, I applied it manually using a recursive function that can actually be used with any view that you want to apply font to all of its TexView child views:

fun applyFont(view: View) {
    if (view is TextView) {
        CalligraphyUtils.applyFontToTextView(context, view, getString(R.string.font_normal))
    }
    if (view is ViewGroup) {
        for (i in 0 until view.childCount) {
            applyFont(view.getChildAt(i))
        }
    }
}

yallam08 avatar Jan 25 '20 12:01 yallam08

Very interesting! Thanks a lot @yallam08

AlejandroHCruz avatar Feb 11 '20 13:02 AlejandroHCruz

NavigationView for the navigation drawer has a similar issue #50. I provided the workaround here which is applicable to the BottomNavigationView as well. Just use itemTextAppearanceActive in addition or instead of itemTextAppearance, depending on your needs.

Stevemaster92 avatar Aug 12 '20 09:08 Stevemaster92

See answer here: https://github.com/InflationX/Calligraphy/issues/50#issuecomment-782143750

chrisjenx avatar Feb 19 '21 15:02 chrisjenx