如何使用自定义字体在DrawerLayout和NavigationView [英] How to use custom fonts in DrawerLayout and NavigationView

查看:233
本文介绍了如何使用自定义字体在DrawerLayout和NavigationView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Android的 DrawerLayout NavigationView 的菜单,但我不知道怎么有菜单项使用自定义字体。有没有人有一个成功的实施?

I want to use Android's DrawerLayout and NavigationView for menus, but I don't know how to have the menu items use a custom font. Does anyone have a successful implementation?

推荐答案

在你的抽屉使用此方法,将基本视图

use this method passing the base view in your drawer

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

这篇关于如何使用自定义字体在DrawerLayout和NavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆