question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Design Support Library support?

See original GitHub issue

I’ve noticed the fonts in the CollapsingToolbarLayout in particular, the Title attribute, isn’t set. I’ve had to resort to something ugly like the following to get it to set the font on it:


public static void modifyCollapsingToolbarTextFont(Context context, CollapsingToolbarLayout collapsingToolbar) {
        // Hack so that the typeface is correct for the title and the title is centered
        try {
            // Get the mCollapsingTextHelper instance
            Field declaredField = collapsingToolbar.getClass().getDeclaredField("mCollapsingTextHelper");
            declaredField.setAccessible(true);
            Object collapsingTextHelper = declaredField.get(collapsingToolbar);

            // The get its mTextPaint field
            Field paintField = collapsingTextHelper.getClass().getDeclaredField("mTextPaint");
            paintField.setAccessible(true);
            TextPaint textPaint = (TextPaint) paintField.get(collapsingTextHelper);

            final Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/FrutigerLTStd-Light.otf");
            textPaint.setTypeface(tf);

        } catch (Exception e) {
            Timber.e(e, "Unexpected error.");
        }
    }

I’d much rather have Calligraphy handle this for me in a nice, unseen, magical way as per usual. I was hoping that the following would just work:


    <style name="TextAppearance.Hero.Title" parent="TextAppearance.AppCompat.Title">
        <item name="fontPath">fonts/FrutigerLTStd_Light.ttf</item>
        <item name="android:textColor">@color/cpb_text_color_error</item>
        <item name="android:textSize">@dimen/hero_font_size</item>
        <item name="android:textStyle">normal</item>
    </style>

And then in the layout:

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:title="Title"
                app:titleEnabled="true"
                app:contentScrim="@android:color/transparent"
                app:expandedTitleMarginBottom="85dp"
                app:expandedTitleGravity="center"
                app:expandedTitleTextAppearance="@style/TextAppearance.Hero.Title"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:statusBarScrim="@android:color/transparent">

But, sadly, it doesn’t set the font.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dsardaricommented, Feb 18, 2016

An alternative method for setting the typeface for the CollapsingToolbarLayout for anyone else that was wondering: http://developer.android.com/reference/android/support/design/widget/CollapsingToolbarLayout.html#setCollapsedTitleTypeface(android.graphics.Typeface)

0reactions
chrisjenxcommented, Jan 30, 2017

Yeah sure, it would be better as a plugin, we are working on making this much more flexible at the moment.

On Mon, 30 Jan 2017 at 10:18 Kusand notifications@github.com wrote:

Drat. Would that be desirable to patch in? I can probably get some bandwidth to do so, and clearance to contribute.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/202#issuecomment-276125402, or mute the thread https://github.com/notifications/unsubscribe-auth/ABHRsQiqbFzaot__9C5iwhszm1f9Ns-5ks5rXhtYgaJpZM4FxTYE .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support Library Packages - Android Developers
The Design Support library adds support for various material design components and patterns for app developers to build upon, such as navigation drawers, ......
Read more >
Android Design Support Library - Android Developers Blog
The Design library, AppCompat, and all of the Android Support Library are important tools in providing the building blocks needed to build a ......
Read more >
Design Support Library | CodePath Android Cliffnotes
At their I/O 2015 conference, Google announced a new design support library, which helps bring a lot of material design components including a...
Read more >
Import new Android Design Support library - Stack Overflow
Hi i'am trying to import the new android support library like this com.android.support:support-design:22.0.0 but i got this error after sync the gradle ...
Read more >
Android Material Design and the Design Support Library
gradle file and add Design Support Library in dependencies section. Sync project. dependencies { compile fileTree(dir: 'libs', include: [' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found