2

When I listen to a YouTube video fullscreen in landscape on my Galaxy Nexus, the navigation bar on the right disapear after a few seconds (the bar which contains the "back", "home" and "recent apps" buttons ).

I want to do the same thing when a user watch a video in my app. What is the code to hide the navigation bar?


[UPDATE] Here is the bar I want to hide. Not the title bar, nor the action bar. The navigation bar. (the bar which contains the "back", "home" and "recent apps" buttons ). I also don't want to "dim" the buttons. I'm looking into removing the bar entirely (like the YouTube app does when you plan a video fullscreen in landscape mode)

enter image description here

Community
  • 1
  • 1
Thierry Roy
  • 8,452
  • 10
  • 60
  • 84

8 Answers8

4

Use:

view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
robert
  • 33,242
  • 8
  • 53
  • 74
Thierry Roy
  • 8,452
  • 10
  • 60
  • 84
  • 1
    Can you elaborate more? From where are you going to take the view? From the Activity? Moreover, is this flag `View.SYSTEM_UI_FLAG_HIDE_NAVIGATION` only for the ICS Android version? Or it is present as well in HoneyComb? – 2dvisio Jul 04 '12 at 11:32
  • @2dvisio SYSTEM_UI_FLAG_HIDE_NAVIGATION is for level 14 and up only (see http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_HIDE_NAVIGATION). And you can take any view in the screen to set this flag) – Thierry Roy Jul 04 '12 at 12:51
  • Thanks. It seems like for Version 3.x there's no chance of doing the same thing.. – 2dvisio Jul 04 '12 at 16:50
  • hi.. scuse me if i reopen question... i try to add that to a Handler that every 3000 millisec recall that method to have bar "always" hided. it works only on app startup then no.. how can i do? – Jayyrus Oct 09 '12 at 18:10
3

The last information I have is that you can use the black tape to cover it. That's the suggestion given by Chet Haase. Watch this google IO 2011 session Q&A starting at 53minutes

Youtube app also dim it, not remove it. It is called light out mode.

View v = findViewById(R.id.view_id);
v.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56
1

SYSTEM_UI_FLAG_HIDE_NAVIGATION flag can be used on a View to hide the navigation bar until a user interaction occurs, starting from Android API 14.

You should look at here and here.

faradaj
  • 3,629
  • 1
  • 22
  • 21
1

This code will hide the navigation bar until you swipe down from the status bar. It's the same method that Jetpack Joyride uses:

View decorView = getWindow().getDecorView(); 
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);

You must also have this in the activity section of your XML file:

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
coder42
  • 13
  • 3
1

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);

If you wont set it sticky bar will be visible again when touch screen will be occured

Munawir
  • 3,346
  • 9
  • 33
  • 51
5er
  • 2,506
  • 7
  • 32
  • 49
0

I use this code to hide the navigation bar and it works perfectly for me

View v = this.getWindow().getDecorView();

v.setSystemUiVisibility(View.INVISIBLE);
tkanzakic
  • 5,499
  • 16
  • 34
  • 41
Sawan Garg
  • 99
  • 1
  • 8
0

Use

View view = this.getWindow().getDecorView();
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
  • While this piece of code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users learn and eventually apply that knowledge to their own code. You are also likely to have positive feedback/upvotes from users, when the code is explained. – Amit Verma Feb 24 '21 at 07:46
0
ActionBar actionBar = getActionBar();
actionBar.hide();

That will do the trick. Also check out the HoneycombGallery example which demonstrates this working.

Mimminito
  • 2,803
  • 3
  • 21
  • 27