private enum State {
EXPANDED,
COLLAPSED,
IDLE
}
private void initViews() {
final String TAG = "AppBarTest";
final AppBarLayout mAppBarLayout = findViewById(R.id.appbar);
mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
private State state;
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (verticalOffset == 0) {
if (state != State.EXPANDED) {
Log.d(TAG,"Expanded");
}
state = State.EXPANDED;
} else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
if (state != State.COLLAPSED) {
Log.d(TAG,"Collapsed");
}
state = State.COLLAPSED;
} else {
if (state != State.IDLE) {
Log.d(TAG,"Idle");
}
state = State.IDLE;
}
}
});
}