Android: Disable and enable to pulling the status bar programmatically for API 19

admin

Administrator
Staff member
I already done do to hide the status bar, but unfortunately I didn't found the way to display it back once its already hide. I did so many workaround but still not success, <a href="https://stackoverflow.com/a/8273225/5065755">here</a> and <a href="https://efransiscus.wordpress.com/2012/04/11/remove-android-status-bar-programmatically/" rel="nofollow noreferrer">here</a>.

<strong>Activity</strong>

Code:
 WindowManager manager = ((WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE));

 WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
 localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
 localLayoutParams.gravity = Gravity.TOP;
 localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|

 // this is to enable the notification to receive touch events
 WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

 // Draws over status bar
 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

 localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
 localLayoutParams.height = (int) (50 * getResources()
                .getDisplayMetrics().scaledDensity);
 localLayoutParams.format = PixelFormat.TRANSPARENT;

 customViewGroup view = new customViewGroup(this);
 manager.addView(view, localLayoutParams);

<strong>customViewGroup class</strong>

Code:
class customViewGroup extends ViewGroup {

    public customViewGroup(Context context) {
        super(context);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
}