使用书法库后,操作栏文本未更改为自定义字体

时间:2016-08-08 10:45:35

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

我正在使用书法图书馆,除了在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:书法:2.2.0'

2 个答案:

答案 0 :(得分:1)

尝试使用Toolbar所述的here。从书法中查看this comment

  

我不支持操作栏,只支持工具栏。这太过分了   保持不然。

答案 1 :(得分:0)

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

此处还可获得更多详情 https://github.com/chrisjenx/Calligraphy/issues/11

希望这会有所帮助。

相关问题