Ukrywanie paska nawigacyjnego
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Z tej lekcji dowiesz się, jak ukryć pasek nawigacyjny, który pojawił się w
Android 4.0 (poziom API 14).
Mimo że ta lekcja skupia się na ukrywaniu
pasek nawigacyjny, zaprojektuj aplikację tak, aby ukryć pasek stanu.
jednocześnie zgodnie z opisem w sekcji Ukrywanie paska stanu.
ukrywanie przycisków nawigacyjnych i pasków stanu (jednocześnie łatwy dostęp do nich);
Dzięki temu treści mogą zajmować całą powierzchnię wyświetlania, co zapewnia bardziej atrakcyjny obraz.
użytkowników.
Rysunek 1. Pasek nawigacyjny.
Ukryj pasek nawigacyjny
Pasek nawigacyjny możesz ukryć za pomocą
flaga SYSTEM_UI_FLAG_HIDE_NAVIGATION
. Ten fragment kodu ukrywa obie
na pasku nawigacyjnym i pasku stanu:
Kotlin
window.decorView.apply {
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
}
Java
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Uwaga:
- Przy tej metodzie dotknięcie dowolnego miejsca na ekranie spowoduje wyświetlenie paska nawigacyjnego (oraz
paska stanu), aby pojawiły się one ponownie i pozostawały widoczne. Interakcja użytkownika powoduje, że flagi stają się
można usunąć.
- Gdy flagi zostaną usunięte, aplikacja musi je zresetować, jeśli
zechce znowu ukryć paski. Informacje znajdziesz w sekcji Reagowanie na zmiany widoczności interfejsu.
jak nasłuchiwać zmian widoczności interfejsu,
aby aplikacja mogła
odpowiednio zareagować.
- Miejsce, w którym ustawiasz flagi interfejsu, ma znaczenie. Jeśli ukryjesz paski systemowe w sekcji aktywności
onCreate()
, a użytkownik naciśnie przycisk Home, paski systemowe będą
które pojawiają się ponownie. Gdy użytkownik ponownie otworzy aktywność, onCreate()
nie zostanie wywołany, więc paski systemowe są nadal widoczne. Jeśli chcesz, aby interfejs systemu zmieniał się na
pozostają aktywne, gdy użytkownik przechodzi do Twojej aktywności i z niej, ustaw flagi UI w
onResume()
lub onWindowFocusChanged()
.
- Tylko metoda
setSystemUiVisibility()
działa, jeśli widok, z którego je wywołujesz, jest widoczny.
- Opuszczenie widoku powoduje pojawienie się flag
ustaw z:
setSystemUiVisibility()
do wyczyszczenia.
Wyświetlanie treści za paskiem nawigacyjnym
W Androidzie 4.1 i nowszych możesz skonfigurować treści aplikacji tak, by były widoczne za
aby zawartość nie zmieniła rozmiaru, ponieważ pasek nawigacyjny jest ukrywany,
programów telewizyjnych. W tym celu użyj
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Może być też konieczne użycie
SYSTEM_UI_FLAG_LAYOUT_STABLE
, aby pomóc aplikacji utrzymać
stabilny układ.
W takim przypadku Twoim obowiązkiem jest zadbanie o to, aby kluczowe elementy
interfejsu aplikacji nie powinny być zasłonięte słupkami systemu. Więcej
na ten temat, patrz
Ukrywanie paska stanu.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-27 UTC."],[],[],null,["# Hide the navigation bar\n\nThis lesson describes how to hide the navigation bar, which was introduced in\nAndroid 4.0 (API level 14).\n\nEven though this lesson focuses on hiding the\nnavigation bar, you should design your app to hide the status bar\nat the same time, as described in [Hiding the Status Bar](/training/system-ui/status).\nHiding the navigation and status bars (while still keeping them readily accessible)\nlets the content use the entire display space, thereby providing a more immersive\nuser experience.\n\n**Figure 1.** Navigation bar.\n\nHide the Navigation Bar\n-----------------------\n\nYou can hide the navigation bar using the\n[SYSTEM_UI_FLAG_HIDE_NAVIGATION](/reference/android/view/View#SYSTEM_UI_FLAG_HIDE_NAVIGATION) flag. This snippet hides both\nthe navigation bar and the status bar: \n\n### Kotlin\n\n```kotlin\nwindow.decorView.apply {\n // Hide both the navigation bar and the status bar.\n // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as\n // a general rule, you should design your app to hide the status bar whenever you\n // hide the navigation bar.\n systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN\n}\n```\n\n### Java\n\n```java\nView decorView = getWindow().getDecorView();\n// Hide both the navigation bar and the status bar.\n// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as\n// a general rule, you should design your app to hide the status bar whenever you\n// hide the navigation bar.\nint uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION\n | View.SYSTEM_UI_FLAG_FULLSCREEN;\ndecorView.setSystemUiVisibility(uiOptions);\n```\n\nNote the following:\n\n- With this approach, touching anywhere on the screen causes the navigation bar (and status bar) to reappear and remain visible. The user interaction causes the flags to be be cleared.\n- Once the flags have been cleared, your app needs to reset them if you want to hide the bars again. See [Responding to UI Visibility Changes](/training/system-ui/visibility) for a discussion of how to listen for UI visibility changes so that your app can respond accordingly.\n- Where you set the UI flags makes a difference. If you hide the system bars in your activity's [onCreate()](/reference/android/app/Activity#onCreate(android.os.Bundle)) method and the user presses Home, the system bars will reappear. When the user reopens the activity, [onCreate()](/reference/android/app/Activity#onCreate(android.os.Bundle)) won't get called, so the system bars will remain visible. If you want system UI changes to persist as the user navigates in and out of your activity, set UI flags in [onResume()](/reference/android/app/Activity#onResume()) or [onWindowFocusChanged()](/reference/android/view/Window.Callback#onWindowFocusChanged(boolean)).\n- The method [setSystemUiVisibility()](/reference/android/view/View#setSystemUiVisibility(int)) only has an effect if the view you call it from is visible.\n- Navigating away from the view causes flags set with [setSystemUiVisibility()](/reference/android/view/View#setSystemUiVisibility(int)) to be cleared.\n\nMake Content Appear Behind the Navigation Bar\n---------------------------------------------\n\nOn Android 4.1 and higher, you can set your application's content to appear behind\nthe navigation bar, so that the content doesn't resize as the navigation bar hides and\nshows. To do this, use\n[SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION](/reference/android/view/View#SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION).\nYou may also need to use\n[SYSTEM_UI_FLAG_LAYOUT_STABLE](/reference/android/view/View#SYSTEM_UI_FLAG_LAYOUT_STABLE) to help your app maintain a\nstable layout.\n\nWhen you use this approach, it becomes your responsibility to ensure that critical parts\nof your app's UI don't end up getting covered by system bars. For more\ndiscussion of this topic, see the [Hiding the Status Bar](/training/system-ui/status#behind) lesson."]]