Reputation: 7994
Does anyone know how to go fullscreen using libgdx
, where the virtual home key buttons on devices such as Nexus are also not visible?
Upvotes: 3
Views: 4259
Reputation: 326
In case anyone finds this like I did while looking for a simple fix you can use
config.useImmersiveMode = true;
on the AndroidApplicationConfiguration
object on 4.4 and up to hide the soft keys in addition to the statusbar (which is hidden by default).
UPDATE: The line belongs in android/src/YOUR/PACKAGE/PATH/android/AndroidLauncher.java
Upvotes: 21
Reputation: 7114
Tried many things and only this code succeeded for me:
...
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
requestWindowFeature(Window.FEATURE_NO_TITLE);
View decorView = getWindow().getDecorView();
decorView.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_STICKY);
initialize(new Soldiers(), cfg);
This is part of MainActivity.java and probably should be executed also on onResume()
.
Upvotes: 0
Reputation: 2695
What you should do is set System Ui Visibility in onResume()
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
Upvotes: 0
Reputation: 7927
libgdx does this for you by default via AndroidApplicationConfiguration#hideStatusBar. However, you can still set to fullscreen.
In the android game project's main activity class:
public class MainActivity extends AndroidApplication {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
//cfg.hideStatusBar = true; //set to true by default
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
}
initialize(new MainClass(), cfg);
}
}
I realized there's a bug where the buttons on the status bar becomes visible after resuming from a locked screen. The workaround is to either use handler to listen(setOnSystemUiVisibilityChangeListener
) for system UI visibility changes and then re-hide the UI if it becomes visible or show the status bar before hiding it as I've done above.
Also View.STATUS_BAR_HIDDEN
(API v11) was renamed to View.SYSTEM_UI_FLAG_LOW_PROFILE
(API v14) which turns the virtual nav buttons into dots. However, both map to the same constant 0x1. Also, as soon as the screen is touched again the buttons will become visible .
If you want to remove the status bar entirely, use View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
(API v14) and Build.VERSION_CODES.ICE_CREAM_SANDWICH
Upvotes: 2