【问题标题】:adding new font android application [duplicate]添加新字体android应用程序[重复]
【发布时间】:2015-10-01 10:03:50
【问题描述】:

我正在尝试向我的 android 应用程序添加自定义字体。 我在“资产”文件夹下添加了字体。 我遇到了允许您以编程方式将其添加到特定视图的代码。 我想将新字体添加到我的整个应用程序并通过我的 style.xml 文件调用它

【问题讨论】:

    标签: android fonts styles


    【解决方案1】:

    首先将字体样式文件添加到 assets 文件夹,然后创建类文件以访问该字体文件。

    FontStyle.java

    public class FontStyle {
        public static Typeface OswaldRegular(Context context) {
            Typeface tf = null;
            try {
                tf = Typeface.createFromAsset(context.getAssets(), "Oswald-Regular.ttf");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return tf;
        }
    }
    

    只需将您的字体文件名替换为上述代码,对于该字体样式,您可以将代码写入 MainActivity.java for

    txt.setTypeface(FontStyle.OswaldRegular(CustomCameraActivity.this));
    

    如果您有任何需要了解的,请随时与我联系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-23
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      相关资源
      最近更新 更多