29

Just wondering how to hide the ICS back/home/etc software buttons programmatically. Just like the Youtube apps does when playing a video. I want to hide them while a video is playing, but bring them up if the user taps the screen.

I can't seem to find it anywhere on the web, or in Google's documentation.

mychemicalro
  • 232
  • 3
  • 21
rustyshelf
  • 44,963
  • 37
  • 98
  • 104

6 Answers6

32

pinxue is spot-on... you want SYSTEM_UI_FLAG_HIDE_NAVIGATION. Example:

myView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

One thing to note, though, is that upon any (and I mean ANY) user interaction the navigation bar will be reshown.

With Honeycomb the closest you can get is to go into "lights out" mode (now called "low profile"... SYSTEM_UI_FLAG_LOW_PROFILE ). This just makes the items on the navigation bar less visible (the little "dots" you've probably seen). If you want to do the best you can at maintain backwards compatibility with Honeycomb you can use reflection to use the "best" method:

// Ask the System Bar to hide
int whichHiddenStatusToUse = android.view.View.STATUS_BAR_HIDDEN;
try {
    // if this next line doesn't thrown an exception then we are on ICS or  
    // above, so we can use the new field.
    whichHiddenStatusToUse = View.class.getDeclaredField("SYSTEM_UI_FLAG_HIDE_NAVIGATION").getInt(mDrawingSurface);
} catch (Exception ex) {
}
// now lets actually ask one of our views to request the decreased visibility
myView.setSystemUiVisibility(whichHiddenStatusToUse);
Jeremy Logan
  • 47,151
  • 38
  • 123
  • 143
  • 7
    The answer is great. Though, I would try to avoid reflection whenever it is possible. Because it is ugly - as usual. I would simply check the current platform version and use one of the constants. E.g. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {...} – Zsolt Safrany Aug 21 '13 at 08:32
  • 1
    Where to get mDrawingSurface? – Nik Feb 04 '14 at 07:32
24

try to setup a Full screen window with flag SYSTEM_UI_FLAG_HIDE_NAVIGATION

pinxue
  • 1,736
  • 12
  • 17
6

You want SYSTEM_UI_FLAG_HIDE_NAVIGATION .

This flag was added as of Ice Cream Sandwich, API 14. Previous to 14 a flag STATUS_BAR_HIDDEN was added in Honeycomb, API 11. Previous to that the soft navigation buttons didn't exist, so fullscreen modes were handled entirely by Themes (specifically Theme.NoTitleBar.Fullscreen).

Use:

if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH )
    mBaseLayout.setSystemUiVisibility( View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
else if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
    mBaseLayout.setSystemUiVisibility( View.STATUS_BAR_HIDDEN );
reor
  • 820
  • 9
  • 22
0

This answer may not be directly answering the question. but i am posting it that it may help others to save time.

I needed to do hide the Nav bar completely. Even when user click the screen it should stay hidden.

Nothing of the above worked for me.

I wrote a class after couple of days of googling this topic long time ago. I end up on this class.

UtilsTaskBar.java

I couldn't test it everywhere, but it works on 4.**

NOTE: I used this class for special purpose applications, which is not for typical users.

If you hide the Navigation bar with this class, it wont be shown again till u restart the device or you show it again with same class.

So use it only if you really need it.

MBH
  • 16,271
  • 19
  • 99
  • 149
  • @yshahak it requires root permission to run those functions, and i did not test it on api23 or higher, thank you for informing. – MBH Dec 08 '16 at 13:28
  • Well, you didn't mention a thing a about rooting... It's a different story then. – yshahak Dec 08 '16 at 13:43
0

in AndroidManifest.xml add this:

<uses-permission android:name="android.permission.BROADCAST_STICKY"/>

then you can use this function to show and hide the home/return navigation bar

private void changeSystemBarVisibilty(boolean show)
{
    Context context = getApplicationContext();
    final Intent intent = new Intent("android.intent.action.SYSTEM_BAR_VISIBILITY");
    intent.putExtra("show", show);
    context.sendStickyBroadcast(intent);
}
Elad
  • 1,523
  • 13
  • 10
-1

It's called "Lights Out Mode" when they talk about it in the apps. I couldn't find anything related to ICS but here's a link to a Honeycomb discussion.

where is api call to do lights out mode in honeycomb

Community
  • 1
  • 1
NKijak
  • 1,174
  • 9
  • 19