Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar title text color

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.

like image 893
Alexey Avatar asked May 09 '17 15:05

Alexey


2 Answers

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"
like image 156
Doron Yakovlev Golani Avatar answered Sep 23 '22 19:09

Doron Yakovlev Golani


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);
like image 43
jmarkstar Avatar answered Sep 24 '22 19:09

jmarkstar