简短的回答:不。Android 没有内置支持通过 XML 将自定义字体应用于文本小部件。
但是,有一种解决方法并不难实现。
第一
您需要定义自己的可样式。在 /res/values 文件夹中,打开/创建 attrs.xml 文件,然后添加一个可声明样式的对象,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="FontText">
        <attr name="typefaceAsset" format="string"/>
    </declare-styleable>
</resources>
第二
假设您希望经常使用此小部件,则应为加载的对象设置一个简单的缓存,因为动态从内存加载它们可能需要一些时间。像这样:Typeface
public class FontManager {
    private static FontManager instance;
    private AssetManager mgr;
    private Map<String, Typeface> fonts;
    private FontManager(AssetManager _mgr) {
        mgr = _mgr;
        fonts = new HashMap<String, Typeface>();
    }
    public static void init(AssetManager mgr) {
        instance = new FontManager(mgr);
    }
    public static FontManager getInstance() {
        if (instance == null) {
            // App.getContext() is just one way to get a Context here
            // getContext() is just a method in an Application subclass
            // that returns the application context
            AssetManager assetManager = App.getContext().getAssets();
            init(assetManager);
        }
        return instance;
    }
    public Typeface getFont(String asset) {
        if (fonts.containsKey(asset))
            return fonts.get(asset);
        Typeface font = null;
        try {
            font = Typeface.createFromAsset(mgr, asset);
            fonts.put(asset, font);
        } catch (Exception e) {
        }
        if (font == null) {
            try {
                String fixedAsset = fixAssetFilename(asset);
                font = Typeface.createFromAsset(mgr, fixedAsset);
                fonts.put(asset, font);
                fonts.put(fixedAsset, font);
            } catch (Exception e) {
            }
        }
        return font;
    }
    private String fixAssetFilename(String asset) {
        // Empty font filename?
        // Just return it. We can't help.
        if (TextUtils.isEmpty(asset))
            return asset;
        // Make sure that the font ends in '.ttf' or '.ttc'
        if ((!asset.endsWith(".ttf")) && (!asset.endsWith(".ttc")))
            asset = String.format("%s.ttf", asset);
        return asset;
    }
}
这个将允许您使用.ttc文件扩展名,但它未经测试。
第三
创建一个子类化 的新类。此特定示例考虑了定义的 XML 字体(、等)并将其应用于字体(假设您使用的是 .ttc 文件)。TextViewbolditalic
/**
 * TextView subclass which allows the user to define a truetype font file to use as the view's typeface.
 */
public class FontText extends TextView {
    public FontText(Context context) {
        this(context, null);
    }
    public FontText(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public FontText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        if (isInEditMode())
            return;
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FontText);
        if (ta != null) {
            String fontAsset = ta.getString(R.styleable.FontText_typefaceAsset);
            if (!TextUtils.isEmpty(fontAsset)) {
                Typeface tf = FontManager.getInstance().getFont(fontAsset);
                int style = Typeface.NORMAL;
                float size = getTextSize();
                if (getTypeface() != null)
                    style = getTypeface().getStyle();
                if (tf != null)
                    setTypeface(tf, style);
                else
                    Log.d("FontText", String.format("Could not create a font from asset: %s", fontAsset));
            }
        }
    }
}
最后
将 XML 中的 实例替换为完全限定的类名。像声明 Android 命名空间一样声明自定义命名空间。请注意,“字体Asset”应指向 /assets 目录中包含的 .ttf 或 .ttc 文件。TextView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.example.FontText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is a custom font text"
        custom:typefaceAsset="fonts/AvenirNext-Regular.ttf"/>
</RelativeLayout>