Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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">
...
like image 917
Ely Avatar asked Jul 11 '18 06:07

Ely


1 Answers

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.

like image 155
Ely Avatar answered Nov 18 '22 12:11

Ely