Change Action Bar color to background color of recycler view item

754 views Asked by At

I have a recycler view with card view as elements.Each card view element has a different card background color.So when I scroll the card view element under the action bar, I want to change the action bar color to background color of that card view.And similarly, the action bar should change its color to the background color next card view as I scroll through the recycler view.Is this possible?

1

There are 1 answers

0
khetanrajesh On BEST ANSWER
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

             int pos = linearLayoutManager.findFirstVisibleItemPosition()
             CardView viewItem = linearLayoutManager.findViewByPosition(pos);
             getSupportActionBar().setBackgroundDrawable(c.getBackground());



        }
    });