Design Support Library support?
See original GitHub issueI’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:
- Created 8 years ago
- Comments:17 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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)
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: