如何在DrawerLayout和NavigationView中使用自定义字体

yds*_*tsh 6 android android-fonts android-menu android-typeface android-drawer

我想使用Android DrawerLayoutNavigationView菜单,但我不知道如何让菜单项使用自定义字体.有没有人成功实施?

Oma*_*oud 3

使用此方法传递抽屉中的基本视图

 public static void overrideFonts(final Context context, final View v) {
    Typeface typeface=Typeface.createFromAsset(context.getAssets(), context.getResources().getString(R.string.fontName));
    try {
        if (v instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) v;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View child = vg.getChildAt(i);
                overrideFonts(context, child);
            }
        } else if (v instanceof TextView) {
            ((TextView) v).setTypeface(typeface);
        }
    } catch (Exception e) {
    }
}
Run Code Online (Sandbox Code Playgroud)