Calligraphy: AppCompat toolbar title font is not set
Hi! I am trying to style toolbar font, but nothing happens. I am able to set font color and style, but not the font itself. I am using the latest calligraphy (2.2.0), appcompat (23.4.0), Android 6.0.
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:title="@string/app_name"
app:titleTextAppearance="@style/DancingWhite"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
...
<style name="DancingWhite" parent="android:TextAppearance">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@color/colorTitle</item>
<item name="android:textStyle">italic</item>
<item name="fontPath">fonts/DancingScript-Regular.otf</item>
</style>
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 23 (2 by maintainers)
Commits related to this issue
- Set proper font of all TextViews on ToolBar Calligraphy currently doesn't support setting of font through styles for ToolBar due to which this hack is necessary. Link to the relevant issue on the Ca... — committed to openedx/edx-app-android by miankhalid 6 years ago
- Set proper font of all TextViews on ToolBar Calligraphy currently doesn't support setting of font through styles for ToolBar due to which this hack is necessary. Link to the relevant issue on the Ca... — committed to openedx/edx-app-android by miankhalid 6 years ago
- Update Fork (#1) * Upgrade Crashlytics * Apply activity visiblity check before showing dialog - LEARNER-1988 * Improvements to delete videos by long press - LEARNER-1288 - SnackBar's vis... — committed to kearabiloe/edx-app-android by kearabiloe 6 years ago
The problem is that Toolbar creates TextViews for title and subtitle programmatically inside itself. It means that it doesn’t use wrapped LayoutInflater by Calligraphy. Instead it uses system Typefaces depending on fontFamily and fontStyle from textAppearence attribute.
But Calligraphy listens for GlobalLayout changes and tries to load style from theme.
So what I’ve done: Add activity theme and customize ActionBarStyle:
+1 here: using calligraphy:2.2.0, appcompat-v7:25.1.1
Everything is set on the toolbar title from the style (color, size) except the font. And I added the attachBaseContext override in the activity.
Nothing worked for me so this is the function that I wrote to workaround the issue:
You can use
android:titleTextAppearanceyou only need to compile above API 20 to use it.On Tue, 28 Jun 2016 at 10:56 Kevin van Mierlo notifications@github.com wrote:
some working sample code would be appreciated, tried to apply the above mentioned method but does not work
We don’t use the
app:titleTextApperancebut theandroid:titleTextApperance