3

I have an app that uses an full screen ImageView. I also use the function below to hide the status bar. But when the user click to the image, the status bar show again. How can prevent the status bar appear on user click?

public void HideStatusBar()
    {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }

myImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HideStatusBar();
            }
        });

This solution works partially. In the first click the status bar appear and the function OnClick() is NOT called. The function is only called in the second click.

1 Answer 1

3

It shows again because of SYSTEM_UI_FLAG_HIDE_NAVIGATION, it will hide it but status bar will reappear when you click on something.

Try this:

public void HideStatusBar()
{
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
1
  • 1
    On Android 4.3 I had the following problem: when the status bar was hidden, the first tap brought the status bar back, but the actual onClick event was not fired. So, if you have a button that closes the activity, then on first tap nothing would happen except for the status bar to reappear. Removing SYSTEM_UI_FLAG_HIDE_NAVIGATION option as mentioned above solved the problem for me. I still have SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION. Commented Apr 2, 2016 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.