How to Hide the Navigation Bar in an Android App
In this article
You can hide the Android navigation bar from inside your app using the system UI visibility APIs or the newer WindowInsetsController. The exact method depends on your target Android version and whether you are using Java or Kotlin. This guide walks through the standard approaches, what to watch out for, and how to bring the bar back when needed. No special tools are required beyond your development environment.
What You'll Need
- Android Studio with a project targeting at least API 21 (Android 5.0 Lollipop) or higher. For the newest APIs, target API 30+.
- A physical device or emulator running Android 5.0 or later to test the behavior.
- Basic familiarity with Activities, Fragments, and the Android lifecycle.
- If you use Kotlin, the AndroidX Core library (androidx.core:core-ktx) for WindowInsetsControllerCompat.
Step-by-Step
- Decide on the hiding behavior. You have two main options: transient hiding (bars reappear on swipe) or sticky hiding (bars stay hidden until you explicitly show them). Transient is simpler and less likely to frustrate users; sticky is better for immersive media or games. Choose based on your app's purpose.
- For Android 11 (API 30) and above, use WindowInsetsController. In your Activity's onCreate or onWindowFocusChanged, call:
WindowCompat.setDecorFitsSystemWindows(window, false)
Then get the controller:val controller = WindowCompat.getInsetsController(window, window.decorView)
Hide the bars:controller.hide(WindowInsetsCompat.Type.navigationBars())
Set the behavior:controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE - For older versions (API 21–29), use the legacy flags. In your Activity, call:
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
This hides both the navigation bar and the status bar if you include the full-screen flag. For navigation bar only, omit SYSTEM_UI_FLAG_FULLSCREEN. - Handle configuration changes. When the bar hides or shows, the layout may resize. Use
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"in your manifest if you want to manage resizing manually, or rely on the default behavior and adjust your layout with insets. - Apply the same logic in a Fragment or Dialog. If you are not in an Activity, get the window from the hosting Activity or Dialog. For a Dialog, call
dialog.window?.let { ... }and apply the same controller or flags. - Restore the bars when appropriate. When leaving immersive mode, call
controller.show(WindowInsetsCompat.Type.navigationBars())or clear the legacy flags withwindow.decorView.systemUiVisibility = 0. Do this in onPause or when the user exits the immersive screen. - Test on multiple API levels. Run your app on an emulator with API 21, API 29, and API 30+ to confirm the bar hides and reappears correctly. Pay attention to gesture navigation versus three-button navigation, as behavior can differ.
Common Mistakes
- Forgetting to set decorFitsSystemWindows to false. On Android 11+, if you do not call
WindowCompat.setDecorFitsSystemWindows(window, false), the hide call may have no effect or cause layout issues. - Using deprecated flags on new Android versions. The
systemUiVisibilityflags are deprecated in API 30. While they may still work, they are not recommended and can behave inconsistently. - Not handling insets. When the navigation bar hides, your content may expand under the status bar or gesture area. Use WindowInsetsCompat to pad your views appropriately.
- Hiding the bar permanently without an escape. Users can get stuck if you use sticky immersive mode and do not provide a way to exit. Always allow a swipe or a button to bring back the bars.
- Ignoring gesture navigation. On devices with gesture navigation, the navigation bar is a thin line; hiding it may not be possible or may require different flags. Test on a device with gesture nav enabled.
Tips
- Use
BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPEfor media apps so users can quickly access system bars without leaving the app. - Combine with
WindowInsetsCompat.Type.statusBars()to hide both bars for a true full-screen experience. - For games, consider using
BEHAVIOR_SHOW_BARS_BY_SWIPE(deprecated but still works on older versions) for a more predictable reveal. - Test with TalkBack enabled to ensure hiding the navigation bar does not break accessibility navigation.
- Keep a reference to the WindowInsetsController if you need to toggle visibility later; you can store it in a field.
Troubleshooting
- The bar does not hide at all. Check that you are calling the hide method after the window is attached (e.g., in onWindowFocusChanged or onResume). Also verify you set decorFitsSystemWindows to false on API 30+.
- The bar reappears immediately. This often happens if you use
SYSTEM_UI_FLAG_IMMERSIVEwithoutSTICKY, or if a focus change resets the flags. UseIMMERSIVE_STICKYfor persistent hiding. - Layout jumps when the bar hides. Use
android:windowSoftInputMode="adjustResize"and handle insets manually to prevent resizing. Alternatively, setandroid:configChangesto avoid activity recreation. - Works on emulator but not on a real device. Some manufacturers (e.g., Xiaomi, Huawei) customize the navigation bar behavior. Test on the target device and consider using the WindowInsetsControllerCompat for consistency.
- App crashes on older Android versions. Ensure you guard API-specific calls with
Build.VERSION.SDK_INTchecks. The WindowInsetsController API is only available from API 30; use the compat version from AndroidX for backward compatibility.
Frequently Asked Questions
Can I hide the navigation bar without hiding the status bar?
Yes. Use WindowInsetsCompat.Type.navigationBars() only, or the legacy flag SYSTEM_UI_FLAG_HIDE_NAVIGATION without SYSTEM_UI_FLAG_FULLSCREEN.
Does hiding the navigation bar affect gestures?
On devices with gesture navigation, the navigation bar is a thin line and may not be hideable. When hidden, the swipe gestures still work, but the visual indicator disappears. Test on a gesture-enabled device.
Will the bar stay hidden after the user swipes?
With BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE, the bar appears temporarily and then auto-hides after a few seconds. With BEHAVIOR_SHOW_BARS_BY_SWIPE (legacy), the bar stays visible until you hide it again.
Is there a way to hide the navigation bar in a specific fragment only?
Yes. Apply the hide logic in the fragment's onResume and restore in onPause. Use the hosting activity's window to get the controller or set flags.
What is the difference between immersive and sticky immersive?
Immersive mode hides the bars but they reappear with a swipe and stay visible. Sticky immersive hides the bars and they auto-hide again after a swipe, keeping the screen immersive.
Can I hide the navigation bar in a WebView?
The WebView itself cannot control system bars. You must hide the bars at the Activity level using the methods above. The WebView will then fill the available space.