38

 enter image description here

When my app starts, I'd like to hide the soft keys bar (in red rectangle) to have a larger screen.

  1. How can I hide it?

  2. Do I need to show the bar purposely when the app quits? Or it will restore itself automatically after the app quits?

Android 4.1, with no hardware keys on phone front.

ohho
  • 50,879
  • 75
  • 256
  • 383
  • possible duplicate of [Hide System Bar in Tablets](http://stackoverflow.com/questions/12605266/hide-system-bar-in-tablets) – jprofitt Apr 30 '13 at 03:30
  • Also possibly helpful: [Easy way to hide system bar on Android ICS](http://stackoverflow.com/questions/10445157/easy-way-to-hide-system-bar-on-android-ics) – jprofitt Apr 30 '13 at 03:30

2 Answers2

53

I know its late but it is the right answer so what you are trying to do is what called immersive mode. for (API 19)

check out: https://developer.android.com/training/system-ui/immersive.html

The code that you were asking for is:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        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_STICKY);
    }
}
mhdjazmati
  • 4,152
  • 1
  • 26
  • 37
29

Try

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

From official doc

The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.

The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.

The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required.

The behavior of the nav bar is app dependent IIRC, so it should show again after the user leaves your app.

MarsAtomic
  • 10,436
  • 5
  • 35
  • 56
  • 2
    Thanks! The above code hides the bar as expected. However, when I touch the screen of the active app, the bar will reappear. How can I make the bar hidden for the rest of the app life cycle? – ohho Apr 30 '13 at 04:19
  • 1
    Any time the user interacts with the app, the nav bar will come back, as you have seen. This is, according to the official doc, intentional behavior. I think you will have to hide the bar every time you expect an interaction, unfortunately. https://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_HIDE_NAVIGATION – MarsAtomic Apr 30 '13 at 04:26
  • 2
    @MarsAtomic Since API level 19 there is SYSTEM_UI_FLAG_IMMERSIVE and SYSTEM_UI_FLAG_IMMERSIVE_STICKY – user457015 Dec 26 '13 at 07:23