Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CollapsingToolbarLayout - setting expandedTitleTextAppearance and collapsedTitleTextAppearance can cause issues

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.

like image 935
bkurzius Avatar asked Jul 02 '15 21:07

bkurzius


1 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

like image 107
bkurzius Avatar answered Oct 13 '22 20:10

bkurzius