user2269164
user2269164

Reputation: 1105

Actionbar text not changed to custom font after using Calligraphy library

I am using Calligraphy library and it working fine except in Actionbar. I am using the below lines for Calligraphy to work

in OnCreate():

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

And

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

Using Above all fonts are customized except in Action Bar. Any other steps need to add?

Tried with below but error saying cannot resolve constructor

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

Any options? Calligraphy version - compile 'uk.co.chrisjenx:calligraphy:2.2.0'

Upvotes: 1

Views: 310

Answers (2)

random
random

Reputation: 10309

Try using a Toolbar as described here. Check this comment from Calligraphy:

I don't support the action bar, only toolbars. It's too much to maintain otherwise.

Upvotes: 1

Neh
Neh

Reputation: 452

You can use a custom view for your action bar (it will display between your icon and your action items). Refer here for what can be done https://recalll.co/app/?q=android%20-%20How%20to%20Set%20a%20Custom%20Font%20in%20the%20ActionBar%20Title?

Also get some more details here https://github.com/chrisjenx/Calligraphy/issues/11

Hope this helps.

Upvotes: 0

Related Questions