Home » Android » android – CollapsingToolbarLayout – setting expandedTitleTextAppearance and collapsedTitleTextAppearance can cause issues

android – CollapsingToolbarLayout – setting expandedTitleTextAppearance and collapsedTitleTextAppearance can cause issues

Posted by: admin June 15, 2020 Leave a comment

Questions:

In the Design Support Library (V 22.2.0), I am having issues setting the expandedTitleTextAppearance and collapsedTitleTextAppearance properties of the CollapsingToolbarLayout .

For example if I set it like this:

<android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:expandedTitleTextAppearance="@style/TransparentText"
        >

and the styles look like this:

<style name="TransparentText">
    <item name="android:textColor">#00000000</item>
</style>
<style name="GreyText">
    <item name="android:textColor">#666666</item>
</style>

The text does not show but when I try to expand the toolbar after it collapses the app will crash on Android 4.1 .

And if I set it to this:

app:expandedTitleTextAppearance="@style/TransparentText"
app:collapsedTitleTextAppearance="@style/GreyText"

It no longer crashes but the text does not show when it collapses.

How to&Answers:

It looks like the styles used for setting expandedTitleTextAppearance and collapsedTitleTextAppearance must extend from TextAppearance.

So everything will work properly if the styles are changed to this:

<style name="TransparentText" parent="@android:style/TextAppearance">
  <item name="android:textColor">#00000000</item>
</style>
<style name="GreyText" parent="@android:style/TextAppearance">
  <item name="android:textColor">#666666</item>
</style>

By the way, since TextView works properly when you set android:TextAppearance without explicitly extending @android:style/TextAppearance, I have logged this as a bug: https://code.google.com/p/android/issues/detail?id=178674