Put transparent title when the toolbar expands on Android

0

I have generated an activity using the template scroll content of android studio, I find that when CollapsingToolbarLayout is expanded, the text of the Toolbar is big and permanent.

I would like it to be transparent when the color of the text is expanded, that is, I made a transition fadeOut and when it collapses fadeIn

    
asked by Webserveis 10.08.2016 в 20:47
source

1 answer

0

I have found a solution if I use code.

In layout in element CollapsingToolbarLayout you can use the properties app:expandedTitleTextAppearance and app:collapsedTitleTextAppearance

but a perculity can not be directly assigned the color, before you must define the styles

in styles.xml define

<style name="ExpandedToolbar" parent="@android:style/TextAppearance">
    <item name="android:textColor">@android:color/transparent</item>
    <item name="android:textSize">32sp</item>
</style>
<style name="CollapsedToobar" parent="@android:style/TextAppearance">
    <item name="android:textColor">@android:color/white</item>
</style>

And now in CollapsingToolbarLayout we assign

app:expandedTitleTextAppearance="@style/ExpandedToolbar"
app:collapsedTitleTextAppearance="@style/CollapsedToobar"

We will get the effect fadeOut to expand and fadeIn when the toolbar collapses

In java code, it is not how it is done, if someone wants to complement it, edit the answer.

Update I see that the color at @color:android/transparent of white turns to gray before fade, the reason is that transparent = #000000 to solve that, if the text of the bar is white its transparent is #00FFFFFF

    
answered by 10.08.2016 / 20:55
source