InflationX / Calligraphy

Custom fonts in Android the easy way...
Apache License 2.0
1.09k stars 82 forks source link

Font not getting applied to PopupMenus or the BottomNavigationView #47

Open AlejandroHCruz opened 4 years ago

AlejandroHCruz commented 4 years ago

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!

yallam08 commented 4 years ago

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

yallam08 commented 4 years ago

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))
        }
    }
}
AlejandroHCruz commented 4 years ago

Very interesting! Thanks a lot @yallam08

Stevemaster92 commented 4 years ago

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.

chrisjenx commented 3 years ago

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