0

i have collapsing toolbar, i want to change its color when it is completely collapsed. what i get is the default color.

here is my 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 & showing the title when toolbar expanded & 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


    });
}  
ahmed
  • 1
  • 4

0 Answers0