android - How do you change the color of collapsing toolbar when it's collapsed? -


i have collapsing toolbar, cannot love of god figure out why not changing color want collapses...here xml code collapsing toolbar.

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/main_content"     android:layout_width="match_parent"     android:layout_height="match_parent">     <android.support.design.widget.appbarlayout         android:id="@+id/appbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/frontiertheme">         <android.support.design.widget.collapsingtoolbarlayout             android:id="@+id/collapsing_toolbar"             android:layout_width="match_parent"             android:layout_height="wrap_content"             app:contentscrim="?attr/colorprimary"             app:layout_scrollflags="scroll|exituntilcollapsed"             app:expandedtitlemarginend="64dp"             app:expandedtitlemarginstart="48dp">             <imageview                 android:layout_width="match_parent"                 android:layout_height="200dp"                 android:scaletype="centercrop"                 app:layout_collapsemode="parallax"                 android:src="@drawable/background"                 android:id="@+id/profileview_imageview"/>             <android.support.v7.widget.toolbar                 xmlns:android="http://schemas.android.com/apk/res/android"                 xmlns:app="http://schemas.android.com/apk/res-auto"                 android:layout_width="match_parent" android:layout_height="wrap_content"                 android:id="@+id/toolbarprofileviewid"                 android:minheight="?attr/actionbarsize"                 app:theme="@style/frontiertheme"                 app:layout_collapsemode="pin">             </android.support.v7.widget.toolbar>         </android.support.design.widget.collapsingtoolbarlayout>         <android.support.design.widget.tablayout             android:id="@+id/tablayout"             android:layout_width="match_parent"             android:layout_height="?attr/actionbarsize"             android:layout_gravity="bottom"             android:background="@color/maincolor"             app:tabmode="scrollable"             app:tabtextcolor="@color/white"/>     </android.support.design.widget.appbarlayout>     <android.support.v4.view.viewpager         android:id="@+id/tab_viewpager"         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.coordinatorlayout> 

here styles.v21 (i dont have have in regular styles.xml file)

<style name="frontiertheme" parent="theme.appcompat.light.noactionbar">         <item name="android:colorprimary">#5f021f</item>         <item name="android:colorprimarydark">#5e152c</item>         <item name="android:coloraccent">#bcbcbc</item>         <item name="android:textcolor">#ffffff</item>     </style> 

and here android manifest.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     package="com.daprlabs.swipedeck" >  <uses-sdk         android:minsdkversion="7"         android:targetsdkversion="23" />   <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:largeheap="true"         android:supportsrtl="true"         android:theme="@style/frontiertheme"         android:name=".applicationenvironment">         <activity             android:name=".activitycenter"> <!--android:theme="@style/testtheme" -->             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>  <activity android:name=".profileview.profileview"             android:label="frontier" />    </application>  </manifest> 

currently, when collapses, color white...but want hexidecimal: #5f021f

add addonoffsetchangedlistener listener in appbarlayout know if it's collapse or not, , change color using setbackgroundcolor. this:

//set listener know current visible state of collapselayout appbarlayout.addonoffsetchangedlistener(new appbarlayout.onoffsetchangedlistener() {     int scrollrange = -1;      @override     public void onoffsetchanged(final appbarlayout appbarlayout, int verticaloffset) {         //initialize size of scroll         if (scrollrange == -1) {             scrollrange = appbarlayout.gettotalscrollrange();         }         //check if view collapsed         if (scrollrange + verticaloffset == 0) {             toolbar.setbackgroundcolor(contextcompat.getcolor(mcontext, r.color.your_collapsed_color));         }else{             toolbar.setbackgroundcolor(contextcompat.getcolor(mcontext, r.color.other_color));         }     } }); 

Comments