Change text style (to bold) in custom style resource for collapsing toolbar layout
Asked Answered
M

1

6

I am using a collapsible toolbar in a project and I am trying to set the textStyle of the expanded collapsing toolbar title to bold.

For some reason I can change pretty much anything using a custom text appearance except textStyle. Does anyone have any information about that issue? I found it hard to search in the internet. I tried programmatically to no avail neither.

<!-- style resource -->
...
<style name="Toolbar_Title" parent="@android:style/TextAppearance.Large">
    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textSize">@dimen/detail_title_text_size</item>
    <item name="android:textStyle">bold</item>
</style>
...

<!-- layout file -->
...
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:expandedTitleMarginBottom="16dp"
        app:expandedTitleMarginStart="16dp"
        app:expandedTitleTextAppearance="@style/Toolbar_Title"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
...
Mishandle answered 11/7, 2018 at 6:40 Comment(0)
M
5

This one works for me. Having defined the text appearance in the layout file for the collapsing toolbar I can use the setExpandedTitleTypeface function to add a bold style to the currently used type face:

mCollapsingToolbarLayout.setExpandedTitleTypeface(Typeface.create(mCollapsingToolbarLayout.getExpandedTitleTypeface(), Typeface.BOLD));

The attribute textStyle does not seem to be taken into account by the collapsing toolbar.

A disadvantage is that the collapsing toolbar by default ellipsizes the title, which may not be a desired behaviour in some cases.

Mishandle answered 11/7, 2018 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.