I am trying to set the main color of AppBarLayout programmatically. XML Layout - AndroidStudio Scrolling Sample:
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:fitsSystemWindows="true" android:layout_height="@dimen/app_bar_height" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout>
And in this operation, I want all the elements inside the AppBarLayout to have a yellow background, so I set:
int barColor = Color.parseColor("#FFC107"); AppBarLayout barLayout = (AppBarLayout) this.findViewById(R.id.app_bar); if (barLayout != null) { barLayout.setBackgroundColor(barColor); } toolbar.setBackgroundColor(barColor); CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) this.findViewById(R.id.toolbar_layout); if (collapsingToolbarLayout != null) { collapsingToolbarLayout.setBackgroundColor(barColor); collapsingToolbarLayout.setContentScrimColor(barColor); }
Everything works fine, except when I scroll halfway through the toolbar (where FAB disappears). In this state, the color of the toolbar is still the default primary color (blue, not yellow), as in this image:

So, two questions:
- Am I missing a method call?
- Any tips on debugging these scripts? In the dump of the Android Device Monitor view hierarchy, I canβt determine which one is the tone colored by this color.
source share