【问题标题】:Actionbar text not changed to custom font after using Calligraphy library使用书法库后,操作栏文本未更改为自定义字体
【发布时间】:2016-08-08 10:45:35
【问题描述】:

我正在使用 Calligraphy 库,除了在 Actionbar 中之外,它工作正常。我正在使用以下几行来进行书法工作

在 OnCreate() 中:

 CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/Regular.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build());

还有

  @Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

使用 除操作栏外,所有字体都是自定义的。还需要添加其他步骤吗?

尝试了以下但错误说无法解析构造函数

    SpannableString s = new SpannableString("My Title");
s.setSpan(new TypefaceSpan(this, "MyTypeface.otf"), 0, s.length(),
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

有什么选择吗?书法版——编译'uk.co.chrisjenx:calligraphy:2.2.0'

【问题讨论】:

    标签: android fonts androiddesignsupport custom-font android-typeface


    【解决方案1】:

    尝试使用Toolbar,如here 所述。检查来自书法的this comment

    我不支持操作栏,只支持工具栏。太多了 否则保持。

    【讨论】:

      【解决方案2】:

      您可以为操作栏使用自定义视图(它将显示在您的图标和操作项之间)。请参阅此处了解可以做什么https://recalll.co/app/?q=android%20-%20How%20to%20Set%20a%20Custom%20Font%20in%20the%20ActionBar%20Title

      还可以在此处获取更多详细信息 https://github.com/chrisjenx/Calligraphy/issues/11

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        相关资源
        最近更新 更多