Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force android libgdx into immersive mode

Following the tutorials on this page(written in 2009) don't work any more. http://www.androidsnippets.com/how-to-make-an-activity-fullscreen

public class FullScreen extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
    }
}

Similarily, trying to change the theme in android.xml has no effect:android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Here is a screenshot: enter image description here

After scouring the web for a few hours, i cant find any articles that can help me. So how, in version 1.5.4 of libgdx, can i get an immersive full screen?

----EDIT---- Here is the now fully working code:

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        hideSystemUi();

        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.hideStatusBar=true;
        config.useImmersiveMode=true;
        initialize(new game(), config);
    }


    private void hideSystemUi() {
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
    }
}
like image 423
Marc Guiselin Avatar asked Sep 29 '22 06:09

Marc Guiselin


1 Answers

Try this in the android activity:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}

Note this will only work on API level 19 or above.

like image 171
Anubian Noob Avatar answered Oct 02 '22 05:10

Anubian Noob