I have the following layout in my application:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:expanded="false">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:contentDescription="@string/app_name"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Also application theme is as following
<style name="Theme.MyApp" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
Where colors are:
<color name="primary">#5677fc</color>
<color name="primary_dark">#303f9f</color>
<color name="accent">#e040fb</color>
To set title I use
CollapsingToolbarLayout collapsingToolbar;
...
collapsingToolbar.setTitle(title);
Title shown black, I what it white. How can I do it?
Both setting app:titleTextColor="@android:color/white"
to Toolbar
and toolbar.setTitleTextColor(0xffffff);
does not help.
I think you should be using setCollapsedTitleTextColor()
:
collapsingToolbar.setCollapsedTitleTextColor(0xffffff);
BTW, your header_image might be taking the whole width of the screen and hiding the title as it has (perhaps it should be wrap_content
):
android:layout_width="match_parent"
Try this
Create a style
<style name="collapsingToolbarLayoutTitleColor" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">18sp</item>
<item name="android:textColor">@color/white</item>
</style>
Then, add the style on your CollapsingToolbarLayout when it is collapsed and expanded.
mCollapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.collapsingToolbarLayoutTitleColor);
mCollapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.collapsingToolbarLayoutTitleColor);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With