chrisjenx / Calligraphy

Custom fonts in Android the easy way...
Apache License 2.0
8.59k stars 1.09k forks source link

subtitleTextStyle not applied when using support v7 Toolbar #413

Open jporombka opened 7 years ago

jporombka commented 7 years ago

Duplicate of #404

I've defined android:actionBarStyle in styles.xml as following:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <!-- Action Bar Theme -->
        <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
    </style>

    <!-- AppTheme ActionBar Style -->
    <style name="AppTheme.ActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TextAppearance.Title</item>
        <item name="android:subtitleTextStyle">@style/AppTheme.ActionBar.TextAppearance.SubTitle</item>
    </style>

    <style name="AppTheme.ActionBar.TextAppearance.Title" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="fontPath">fonts/Pacifico-Regular.ttf</item>
    </style>

    <style name="AppTheme.ActionBar.TextAppearance.SubTitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
        <item name="fontPath">fonts/Roboto-Light.ttf</item>
    </style>

The titleTextView has the font applied defined with android:titleTextStyle. However, the font defined with android:subtitleTextStyle is NOT applied to the subtitleTextView. Instead the subtitleTextView has the titleTextView's font applied.

After debugging a little bit, I think I found the reason: When encountering a Toolbar, the titleTextView and subtitleTextView are both assigned the string " " (for determining the view type later). After that, onViewCreatedInternal() is called for the Toolbar's children applying the font defined by "fontPath" in the corresponding text style. When determining the view type, i.e. titleTextView or subtitleTextView, the isActionBarTitle() method returns "true" for both views, resulting in titleTextStyle style being applied to both titleTextView and subtitleTextView. The isActionBarTitle() method compares the textView's getText() with the parent Toolbar's getTitle() value, which is also true when the view being checked is the subtitleTextView since both the title and subtitle have the same value (" ") assigned.

Instead, the titleTextView and subtitleTextView should be assigned different strings in order to determine the view type correctly.