Toggle Fullscreen mode

bwoogie picture bwoogie · Oct 7, 2011 · Viewed 15.1k times · Source

I need some help toggling fullscreen mode. I have a setting in a preference screen to go fullscreen. In my main activity's onResume I have:

if(mFullscreen == true) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

            } else
            {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

            }

But this doesn't seem to work because it needs to be called before setContentView right?

... But Also, I have requestWindowFeature(Window.FEATURE_NO_TITLE); before setContentView and it takes away the title AND status bar... Can anybody offer some help?

---Edit--- Ok, I had a bug that was causing this to not work. So it actually does. Now, I just need to know how to toggle the title bar.

Answer

cprcrack picture cprcrack · Apr 26, 2013
private void setFullscreen(boolean fullscreen)
{
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    if (fullscreen)
    {
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    else
    {
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    getWindow().setAttributes(attrs);
}