إخفاء شريط التنقل
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يصف هذا الدرس كيفية إخفاء شريط التنقل، والذي تم تقديمه في
Android 4.0 (المستوى 14)
على الرغم من أن هذا الدرس يركز على إخفاء
شريط التنقل، يجب تصميم تطبيقك لإخفاء شريط الحالة
في الوقت نفسه، على النحو الموضّح في إخفاء شريط الحالة.
إخفاء أشرطة التنقل والحالة (مع الاحتفاظ بإمكانية الوصول إليها بسهولة)
المحتوى يستخدم مساحة العرض بأكملها، ما يوفّر تجربة غامرة أكثر
تجربة المستخدم.
الشكل 1. شريط التنقل.
إخفاء شريط التنقل
يمكنك إخفاء شريط التنقل باستخدام
علم واحد (SYSTEM_UI_FLAG_HIDE_NAVIGATION
) يخفي هذا المقتطف كلاً من
شريط التنقل وشريط الحالة:
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);
ملاحظات:
- باستخدام هذا النهج، يؤدي لمس أي مكان على الشاشة إلى ظهور شريط التنقل (
ليظهر مجددًا ويظل مرئيًا. يتسبب تفاعل المستخدم في وضع العلامات
.
- بعد محو العلامات، يحتاج تطبيقك إلى إعادة ضبطها في حال:
وتريد إخفاء الأشرطة مرة أخرى. راجِع الاستجابة لتغييرات مستوى رؤية واجهة المستخدم للاطّلاع على
كيفية الاستماع إلى التغييرات في مستوى رؤية واجهة المستخدم حتى يتمكن التطبيق
والاستجابة وفقًا لذلك.
- يُحدث المكان الذي تضع فيه علامات واجهة المستخدم فرقًا. إذا أخفيت أشرطة النظام في قسم
onCreate()
ويضغط المستخدم على الصفحة الرئيسية، فإن أشرطة النظام
من جديد. عندما يعيد المستخدم فتح النشاط، onCreate()
.
فلن يتم استدعاء الإجراء، لذلك ستظل أشرطة النظام مرئية. إذا كنت تريد إجراء تغييرات على واجهة مستخدم النظام
بينما ينتقل المستخدم إلى نشاطك وخارجه، اضبط علامات واجهة المستخدم في
onResume()
أو onWindowFocusChanged()
.
- الطريقة
setSystemUiVisibility()
فقط
إذا كانت طريقة العرض التي تتصل منها مرئية.
- يؤدي الانتقال بعيدًا عن العرض إلى ظهور علامات
تم الضبط باستخدام
setSystemUiVisibility()
ليتم مسحه.
إظهار المحتوى خلف شريط التنقل
في نظام التشغيل Android 4.1 والإصدارات الأحدث، يمكنك ضبط محتوى التطبيق ليظهر في الإصدارات
شريط التنقل، بحيث لا يتم تغيير حجم المحتوى حيث يختفي شريط التنقل
للقيام بذلك، استخدم
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
قد تحتاج أيضًا إلى استخدام
SYSTEM_UI_FLAG_LAYOUT_STABLE
لمساعدة تطبيقك في الحفاظ على
تخطيط ثابت.
عند استخدام هذا النهج، تصبح مسئولية ضمان تنفيذ الأجزاء المهمة
من واجهة المستخدم في تطبيقك لا تغطيها أشرطة النظام. لمزيد من المعلومات،
مناقشة هذا الموضوع، راجع
إخفاء درس شريط الحالة:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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."]]