Skip to content Skip to sidebar Skip to footer

Action Bar Is Hidden And That Shown Instantly After That

I'm trying to toggle show/hide action bar on user click on activity, so I've implemented this functionality like this in activity: @Override public boolean dispatchTouchEvent(Motio

Solution 1:

I think dispatchTouchEvent might be called two time on touch down and up action so take one boolean flag and check this flag value before showing action bar :

private boolean isManuallyHideShownActionBar;

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    super.dispatchTouchEvent(ev);

    ActionBar actionBar = getSupportActionBar();

    if(!isManuallyHideShownActionBar){
        if (actionBar.isShowing()) {
            actionBar.hide();
        } else {
            actionBar.show();
        }
        isManuallyHideShownActionBar = true;
    }else{
        isManuallyHideShownActionBar = false;
    }

    return true;
}

Post a Comment for "Action Bar Is Hidden And That Shown Instantly After That"