How to hide / show toolbar when clicking on a view?
2 answers
If the toolbar is used independently, then you can use the setVisibility method as for a regular View. When used as an ActionBar (done by setSupportActionBar (..)), use the Show and Hide methods of the ActionBar.
- Thanks so much for the help - Ivan Chmyr
If someone needs it, this is the solution that helped me.
public void initToolbar () {toolbar = (Toolbar) findViewById (R.id.toolBar); setSupportActionBar (toolbar); this.getSupportActionBar (). setDisplayShowTitleEnabled (false); setTitle (getString (R.string.appName)); toolbar.setTitleTextColor (getResources (). getColor (android.R.color.white)); }
private void toggleToolbarVisibility () {if (isToolbarVisible) {toolbar.setVisibility (View.INVISIBLE); } else {toolbar.setVisibility (View.VISIBLE); } isToolbarVisible =! isToolbarVisible; }
private class TapGestureListener extends GestureDetector.SimpleOnGestureListener {@Override public boolean onSingleTapConfirmed (MotionEvent e) {toggleToolbarVisibility (); return super.onSingleTapConfirmed (e); }}