Currently I have an image on a profile screen and StatusBar is "transparent". Running right!
Problem:
The problem is with the scrolling of the screen, because in this case I have already been able to make the Color of the StatusBar in PrimaryDark color - when scrolling (up).
Code: I'm using this template
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_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
});
What does not work: When scrolling the screen (down) I have a Toolbar that is fixed. When it finishes loading the data of RecyclerView
, then yes it returns to the original state. (with transparency)
But it has a certain transparency, in that roll back. (prints below)
I need to somehow identify when return rollout occurs and set the colorPrimaryDark.
Ex:
- Expanded:
- Collapsed: