I have implemented Show/Hide Toolbar when the user scrolls the list using CoordinatorLayout
. And now I am working Show/Hide Toolbar in android app on user touch anywhere on the screen. I have tried this code and it is working fine:
if (toolbar.getVisibility() == View.VISIBLE) {
toolbar.setVisibility(View.GONE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
toolbar.setVisibility(View.VISIBLE);
}
But the only problem is that toolbar does not animate while hiding or showing. I want that toolbar should slide up and slide down while hiding and showing.
if (toolbar.getVisibility() == View.VISIBLE) {
appbar.animate().translationY(-112).setDuration(600L)
.withEndAction(new Runnable() {
@Override
public void run() {
toolbar.setVisibility(View.GONE);
}
}).start();
} else {
toolbar.setVisibility(View.VISIBLE);
appbar.animate().translationY(0).setDuration(600L).start();
}