نوار ناوبری را مخفی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این درس نحوه پنهان کردن نوار ناوبری را که در اندروید 4.0 (سطح API 14) معرفی شده است، توضیح می دهد.
حتی اگر این درس بر پنهان کردن نوار پیمایش تمرکز دارد، باید برنامه خود را طوری طراحی کنید که نوار وضعیت را همزمان پنهان کند، همانطور که در پنهان کردن نوار وضعیت توضیح داده شده است. پنهان کردن نوارهای پیمایش و وضعیت (در حالی که همچنان آنها را به راحتی در دسترس نگه میدارد) به محتوا اجازه میدهد از کل فضای نمایش استفاده کند و در نتیجه تجربه کاربر فراگیرتری را ارائه دهد.

شکل 1. نوار ناوبری.
نوار ناوبری را مخفی کنید
می توانید نوار پیمایش را با استفاده از پرچم SYSTEM_UI_FLAG_HIDE_NAVIGATION
پنهان کنید. این قطعه هم نوار پیمایش و هم نوار وضعیت را پنهان می کند:
کاتلین
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
}
جاوا
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);
به موارد زیر توجه کنید:
- با این رویکرد، لمس هر نقطه از صفحه باعث می شود نوار ناوبری (و نوار وضعیت) دوباره ظاهر شود و قابل مشاهده باشد. تعامل کاربر باعث پاک شدن پرچم ها می شود.
- هنگامی که پرچم ها پاک شدند، اگر می خواهید دوباره نوارها را پنهان کنید، برنامه شما باید آنها را بازنشانی کند. برای بحث در مورد نحوه گوش دادن به تغییرات نمایان بودن UI به طوری که برنامه شما بتواند مطابق با آن پاسخ دهد، به پاسخ به تغییرات نمایان بودن رابط کاربری مراجعه کنید.
- جایی که پرچمهای رابط کاربری را تنظیم میکنید تفاوت ایجاد میکند. اگر نوارهای سیستم را در متد
onCreate()
فعالیت خود پنهان کنید و کاربر Home را فشار دهد، نوارهای سیستم دوباره ظاهر می شوند. هنگامی که کاربر فعالیت را دوباره باز می کند، onCreate()
فراخوانی نمی شود، بنابراین نوارهای سیستم قابل مشاهده خواهند بود. اگر می خواهید تغییرات رابط کاربری سیستم در حین حرکت کاربر به داخل و خارج از فعالیت شما ادامه پیدا کند، پرچم های رابط کاربری را در onResume()
یا onWindowFocusChanged()
تنظیم کنید. - متد
setSystemUiVisibility()
فقط در صورتی اثر دارد که نمایی که از آن فراخوانی می کنید قابل مشاهده باشد. - دور شدن از view باعث می شود پرچم های تنظیم شده با
setSystemUiVisibility()
پاک شوند.
محتوا را در پشت نوار پیمایش ظاهر کنید
در اندروید 4.1 و بالاتر، میتوانید محتوای برنامهتان را طوری تنظیم کنید که در پشت نوار پیمایش ظاهر شود تا با پنهان شدن و نمایش نوار پیمایش، اندازه محتوا تغییر نکند. برای انجام این کار، از SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
استفاده کنید. همچنین ممکن است لازم باشد از SYSTEM_UI_FLAG_LAYOUT_STABLE
برای کمک به برنامه خود برای حفظ یک طرح بندی پایدار استفاده کنید.
وقتی از این رویکرد استفاده میکنید، این وظیفه شماست که مطمئن شوید بخشهای مهم رابط کاربری برنامهتان توسط نوارهای سیستم پوشش داده نمیشوند. برای بحث بیشتر در مورد این موضوع، به درس پنهان کردن نوار وضعیت مراجعه کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]