Android 如何在设置中指定字体文件而不是代码?

Android 如何在设置中指定字体文件而不是代码?,android,android-typeface,Android,Android Typeface,我正在尝试装饰我的应用程序字体。我可以通过代码来完成。但不知道如何在设置中执行此操作。在代码中,我这样做 public class Fonts { public static Typeface getHeaderFont(Context context){ return Typeface.createFromAsset(context.getAssets(), "header_levelI.ttf"); } public static Typeface g

我正在尝试装饰我的应用程序字体。我可以通过代码来完成。但不知道如何在设置中执行此操作。在代码中,我这样做

public class Fonts {
    public static Typeface getHeaderFont(Context context){
        return Typeface.createFromAsset(context.getAssets(), "header_levelI.ttf");
    }
    public static Typeface getSubHeaderFont(Context context){
        return Typeface.createFromAsset(context.getAssets(), "header_levelII.ttf");
    }
}


设置android studio仅标准字体。如何在文件中指定字体以不写入额外代码?

使用自定义字体创建自定义文本视图

注意:将所需字体文件放在assets/fonts目录中非常重要

public class CustomTextView extends TextView {
    public CustomTextView(Context context) {
        super(context);
        setFont();
    }
    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFont();
    }
    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setFont();
    }

    private void setFont() {
        Typeface font = Typeface.createFromAsset(getContext().getAssets(),"fonts/ss-symbolicons-line.ttf");
        setTypeface(font, Typeface.NORMAL);
    }
}

不幸的是,目前不支持它…请检查:@hareshchelana是正确的。如果链接解决了问题,+1&将您的评论作为一个重要问题提出flag@RIT,你可以通过放弃投票和感谢来感激。@Hareshchelana谢谢。这有帮助
public class CustomTextView extends TextView {
    public CustomTextView(Context context) {
        super(context);
        setFont();
    }
    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFont();
    }
    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setFont();
    }

    private void setFont() {
        Typeface font = Typeface.createFromAsset(getContext().getAssets(),"fonts/ss-symbolicons-line.ttf");
        setTypeface(font, Typeface.NORMAL);
    }
}