Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtitleTextStyle not applied when using support v7 Toolbar #413

Open
jporombka opened this issue Sep 2, 2017 · 0 comments
Open

subtitleTextStyle not applied when using support v7 Toolbar #413

jporombka opened this issue Sep 2, 2017 · 0 comments

Comments

@jporombka
Copy link

jporombka commented Sep 2, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant