title: change the color of toolbar when it is collapsed in android
body: <p>i have collapsing toolbar, i want to change its color when it is completely collapsed. what i get is the default color. </p>
  
  <p>here is my code </p>
  
  <pre><code>  private void initCollapsingToolbar() {
      final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
      // collapsingToolbar.setTitle(" ");
      AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
      // appBarLayout.setExpanded(true);
  
      // hiding &amp; showing the title when toolbar expanded &amp; collapsed
  
      appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
          @SuppressLint("ResourceAsColor")
          @Override
          public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
              int scrollRange = -1;
              if (scrollRange == -1) {
                  scrollRange = appBarLayout.getTotalScrollRange();
              }
              //Check if the view is collapsed
              if (scrollRange == 0) {
                  toolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
              } else {
                 // toolbar.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
              }
          }
  
  
  
  
          //Initialize the size of the scroll
  
  
      });
  }  
  </code></pre>