2

I'm trying to hide the navigation bar, using methods I've found described on the internet.

I have a simple layout which shows a WebView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:id="@+id/layout" >

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</RelativeLayout>

The code that I'm using at app startup is:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    web.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

But this doesn't hide the navigation bar.

I've added...

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

... to my activity too.

How can I achieve this?

TZHX
  • 5,291
  • 15
  • 47
  • 56
Jayyrus
  • 12,961
  • 41
  • 132
  • 214
  • Hi, I'm still having problems with this I get a gap at the bottom of the screen for devices such as the Nexus 7 & Nexus 10. – Golan Shay Feb 07 '17 at 10:13

4 Answers4

8

you can hide the navigationbar,try this

public void FullScreencall() {
    if(Build.VERSION.SDK_INT < 19) //19 or above api
        View v = this.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else {
            //for lower api versions.
        View decorView = getWindow().getDecorView(); 
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }
}
Evish Verma
  • 1,037
  • 9
  • 4
4

You cannot permanently hide the system bar on a tablet.

SYSTEM_UI_FLAG_HIDE_NAVIGATION on Android 4.1 and higher will hide the system bar, but it will reappear as soon as the user does anything.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yes its doing the same as u said. But I want to finish the activity on userInteraction method . But its not functioning properly its finishing my activity after two clicks on the activity – Qadir Hussain Nov 29 '13 at 05:28
0

You can not hide the navigation bar within the given framework. However, there is a work around if rooting the device is an option for you:

  1. Root device

  2. Install and run Busybox

  3. Install HideBar

In HideBar there is an option to run in 'Kiosk' mode, in which there is no way to re-display the navigation bar. Needless to say, you really need to be careful with this.


ılǝ
  • 3,440
  • 2
  • 33
  • 47
  • 2
    @JohnyTex not sure, try: http://bit.ly/1CLKCf9 This is pretty old now, I don't this answer is relevant any more – ılǝ Mar 24 '15 at 12:47
0

May be this helps:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setUiOptions(//
    View.SYSTEM_UI_FLAG_FULLSCREEN|//
    View.SYSTEM_UI_FLAG_IMMERSIVE|//
    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    setContentView(R.layout.main);

    findViewById(R.id.main).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            v.setSystemUiVisibility(//
                View.SYSTEM_UI_FLAG_FULLSCREEN|//
                View.SYSTEM_UI_FLAG_IMMERSIVE|//
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        }
    });
}
Sebastian Annies
  • 2,438
  • 1
  • 20
  • 38
  • While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – Waqar UlHaq Feb 21 '20 at 13:44