'Android "app:titleTextColor" Doesn't Work in MaterialToolbar within CollapsingToolbarLayout
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/purple_500"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/sam" />
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:title="Sam Chen"
app:titleTextColor="@color/white"/> //<- here, doesn't work
</com.google.android.material.appbar.CollapsingToolbarLayout>
Result:
And collapsed:
androidmaterial-designandroid-toolbarandroid-collapsingtoolbarlayoutandroid-appbarlayoutselectknockout.jsbindingobservabledropdown
Solution 1:[1]
Here is my solution for my case, I just need the title and options menu icon to be white:
<com.google.android.material.appbar.CollapsingToolbarLayout
...
android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">
For customizing color of title and options menu icon can read this: How to change the Text color of collapsing toolbar and the back button color of collapsing toolbar in android
Solution 2:[2]
<com.google.android.material.appbar.CollapsingToolbarLayout
...
app:collapsedTitleTextColor="@android:color/white"
app:expandedTitleTextColor="@android:color/white">
Solution 3:[3]
For anyone else who is struggling with the same issue, I have solved this with the following, I believe the issue was that I was trying to call the bindings twice, instead of creating one variable and controlling it all there.
Are you human?<br><select data-bind="value: selectedChoice">
<option value="none">Select answer</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<p data-bind="visible: selectedChoice() === 'yes'">
Are you employed?<br>
<select data-bind="value: currentSelect">
<option value="blank">none</option>
<option value="form">show form</option>
<option value="sorry">Something else</option>
</select></p>
<br><br>
<p data-bind="visible:currentSelect() === 'blank'"> </p>
<p data-bind="visible:currentSelect() === 'form'">Hello, now display the sign up form</p>
<p data-bind="visible:currentSelect() === 'sorry'">Goodbye</p>
<script>
var viewModel = {
selectedChoice: ko.observable("none"),
currentSelect: ko.observable("none")
};
ko.applyBindings(viewModel);
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sam Chen |
| Solution 2 | SuMumo |
| Solution 3 | User2344 |


