Hide ICS back home task switcher buttons
Asked Answered
T

6

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.

Tachygraphy answered 12/12, 2011 at 1:50 Comment(0)
A
24

try to setup a Full screen window with flag SYSTEM_UI_FLAG_HIDE_NAVIGATION

Accessary answered 12/12, 2011 at 2:8 Comment(1)
Is this necessary to call this on root view?Merriott
R
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);
Riesman answered 3/1, 2012 at 3:20 Comment(2)
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) {...}Kershner
Where to get mDrawingSurface?Slat
A
24

try to setup a Full screen window with flag SYSTEM_UI_FLAG_HIDE_NAVIGATION

Accessary answered 12/12, 2011 at 2:8 Comment(1)
Is this necessary to call this on root view?Merriott
O
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 );
Overmuch answered 11/11, 2013 at 15:8 Comment(0)
A
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.

Aurelie answered 27/1, 2016 at 10:12 Comment(2)
@yshahak it requires root permission to run those functions, and i did not test it on api23 or higher, thank you for informing.Aurelie
Well, you didn't mention a thing a about rooting... It's a different story then.Ezra
S
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);
}
Scullion answered 22/9, 2016 at 19:51 Comment(0)
H
-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

Heathendom answered 12/12, 2011 at 22:26 Comment(1)
That just turns them into the little "dots", doesn't actually hide them (like the aforementioned YouTube app).Riesman

© 2022 - 2024 — McMap. All rights reserved.