Statusbar - Change color with scrolling on a Collapsingtoolbar

Asked

Viewed 19 times

1

Currently I have an image on a profile screen and Statusbar is "transparent". Running straight!!

Problem:

The problem is the scrolling of the screen, because in this case I’ve managed to make the color of the Statusbar stay in the color Primarydark - when scrolling (up).

Code: I’m using this model

AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout_edit_profile);
        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            boolean isShow = false;
            int scrollRange = -1;

            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (scrollRange == -1) {
                    scrollRange = appBarLayout.getTotalScrollRange();
                }
                if (scrollRange + verticalOffset == 0) {       
                      Window window = activity.getWindow();
                      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

                      window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                      window.setStatusBarColor(activity.getResources().getColor(R.color.primary_color));


                    isShow = true;
                } else if (isShow) {
                    collapsingToolbarLayout.setTitle(" ");
                    isShow = false;
                    Window w = activity.this.getWindow(); 
                    w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATU‌​S, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                }
            }
        });

What doesn’t work: When scrolling the screen (down) I have a Toolbar that stays fixed. When you finish loading the data from RecyclerView, ai yes back to the original state. (with transparency)

But it is with a certain transparency, this scrolling back. (prints below)

I need to somehow identify when the return scroll happens and set the corPrimaryDark.

Ex:

  • Expanded:

inserir a descrição da imagem aqui

  • Collapsed:

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.