ascallonisi
ascallonisi

Reputation: 941

Android action bar hide and show on top-down swipe

I'm developing an Android fulscreen activity, and I would like to be able to show and hide the Action Bar exactly like I'm doing with the navigation menu.

Currently I have set only the setSystemUiVisibility and

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY                        
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); 

an this to permanently hide the action bar:

android.app.ActionBar actionBar = getActionBar();
actionBar.hide();

But how can I get it to slide when the user swipes from the top down, like the navigation bar does?

Upvotes: 1

Views: 5690

Answers (1)

sarath kumar
sarath kumar

Reputation: 144

if your app is in full screen mode.the top most view in the layout need to implement OnTouchListener, and now we can get the motion such as swipe down, up etc ..and if when the user swipe down you need to invoke actionBar.show(); which will make actionbar visible. for example if you have a toolbar at the topmost of the layout...

  Toolbar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()){
                case MotionEvent.ACTION_DOWN:

                    actionBar.show();
            }
            return false;
        }
    });

Upvotes: 1

Related Questions