نوار وضعیت را مخفی کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این درس نحوه پنهان کردن نوار وضعیت را در نسخههای مختلف اندروید توضیح میدهد. پنهان کردن نوار وضعیت (و به صورت اختیاری، نوار پیمایش) به محتوا اجازه میدهد تا از فضای نمایش بیشتری استفاده کند و در نتیجه تجربه کاربری همهجانبهتری را ارائه دهد.
شکل 1 یک برنامه با نوار وضعیت قابل مشاهده را نشان می دهد:

شکل 1. نوار وضعیت قابل مشاهده.
شکل 2 یک برنامه با نوار وضعیت پنهان را نشان می دهد. توجه داشته باشید که نوار عمل نیز مخفی است. هرگز نباید نوار اقدام را بدون نوار وضعیت نشان دهید.

شکل 2. نوار وضعیت پنهان.
نوار وضعیت را در اندروید 4.0 و پایینتر مخفی کنید
میتوانید نوار وضعیت را در اندروید 4.0 (سطح API 14) و پایینتر با تنظیم پرچمهای WindowManager
پنهان کنید. می توانید این کار را به صورت برنامه ریزی شده یا با تنظیم یک موضوع فعالیت در فایل مانیفست برنامه خود انجام دهید. اگر نوار وضعیت همیشه باید در برنامه شما پنهان بماند، تنظیم یک طرح زمینه فعالیت در فایل مانیفست برنامه شما ترجیح داده می شود (اگرچه به طور دقیق، اگر بخواهید می توانید طرح زمینه را به صورت برنامه نویسی لغو کنید). به عنوان مثال:
<application
...
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
مزایای استفاده از یک موضوع فعالیت به شرح زیر است:
- نگهداری آن آسانتر و خطای کمتری نسبت به تنظیم یک پرچم به صورت برنامهریزی شده است.
- این منجر به انتقال نرمافزار رابط کاربری میشود، زیرا سیستم اطلاعاتی را دارد که برای ارائه رابط کاربری شما قبل از شروع فعالیت اصلی برنامه شما نیاز دارد.
از طرف دیگر، میتوانید پرچمهای WindowManager
به صورت برنامهنویسی تنظیم کنید. این رویکرد پنهان کردن و نشان دادن نوار وضعیت را هنگام تعامل کاربر با برنامه شما آسان تر می کند:
کاتلین
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
setContentView(R.layout.activity_main)
}
...
}
جاوا
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
...
}
هنگامی که پرچمهای WindowManager
را تنظیم میکنید (چه از طریق یک موضوع فعالیت یا برنامهای)، پرچمها به قوت خود باقی میمانند مگر اینکه برنامه شما آنها را پاک کند.
میتوانید از FLAG_LAYOUT_IN_SCREEN
برای تنظیم طرحبندی فعالیت خود برای استفاده از همان ناحیه صفحه استفاده کنید که در هنگام فعال کردن FLAG_FULLSCREEN
در دسترس است. هنگامی که نوار وضعیت پنهان و نمایش داده می شود، این کار از تغییر اندازه محتوای شما جلوگیری می کند.
نوار وضعیت را در اندروید 4.1 و بالاتر مخفی کنید
با استفاده از setSystemUiVisibility()
می توانید نوار وضعیت را در اندروید 4.1 (سطح API 16) و بالاتر مخفی کنید. setSystemUiVisibility()
پرچم های رابط کاربری را در سطح نمای فردی تنظیم می کند. این تنظیمات در سطح پنجره جمع می شوند. استفاده از setSystemUiVisibility()
برای تنظیم پرچمهای UI به شما کنترل دقیقتری بر روی نوارهای سیستم میدهد تا استفاده از پرچمهای WindowManager
. این قطعه نوار وضعیت را پنهان می کند:
کاتلین
// Hide the status bar.
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
actionBar?.hide()
جاوا
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
به موارد زیر توجه کنید:
- هنگامی که پرچمهای رابط کاربری پاک شدند (مثلاً با دور شدن از فعالیت)، اگر میخواهید دوباره نوارها را پنهان کنید، برنامه شما باید آنها را بازنشانی کند. برای بحث در مورد نحوه گوش دادن به تغییرات نمایان بودن UI به طوری که برنامه شما بتواند مطابق با آن پاسخ دهد، به پاسخ به تغییرات نمایان بودن رابط کاربری مراجعه کنید.
- جایی که پرچمهای رابط کاربری را تنظیم میکنید تفاوت ایجاد میکند. اگر نوارهای سیستم را در متد
onCreate()
فعالیت خود پنهان کنید و کاربر Home را فشار دهد، نوارهای سیستم دوباره ظاهر می شوند. هنگامی که کاربر فعالیت را دوباره باز می کند، onCreate()
فراخوانی نمی شود، بنابراین نوارهای سیستم قابل مشاهده خواهند بود. اگر می خواهید تغییرات رابط کاربری سیستم در حین حرکت کاربر به داخل و خارج از فعالیت شما ادامه پیدا کند، پرچم های رابط کاربری را در onResume()
یا onWindowFocusChanged()
تنظیم کنید. - متد
setSystemUiVisibility()
فقط در صورتی اثر دارد که نمایی که از آن فراخوانی می کنید قابل مشاهده باشد. - دور شدن از view باعث می شود پرچم های تنظیم شده با
setSystemUiVisibility()
پاک شوند.
کاری کنید که محتوا در پشت نوار وضعیت ظاهر شود
در اندروید 4.1 و بالاتر، میتوانید محتوای برنامهتان را طوری تنظیم کنید که در پشت نوار وضعیت نمایش داده شود تا با پنهان شدن و نمایش نوار وضعیت، اندازه محتوا تغییر نکند. برای انجام این کار، از SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
استفاده کنید. همچنین ممکن است لازم باشد از SYSTEM_UI_FLAG_LAYOUT_STABLE
برای کمک به برنامه خود برای حفظ یک طرح بندی پایدار استفاده کنید.
وقتی از این روش استفاده میکنید، این وظیفه شماست که مطمئن شوید بخشهای مهم رابط کاربری برنامهتان (مثلاً کنترلهای داخلی در برنامه Maps) توسط نوارهای سیستم پوشش داده نمیشوند. این می تواند برنامه شما را غیرقابل استفاده کند. در بیشتر موارد، میتوانید با افزودن ویژگی android:fitsSystemWindows
به فایل طرحبندی XML خود، با تنظیم روی true
، این کار را انجام دهید. این بالشتک ViewGroup
والد را تنظیم می کند تا فضایی برای پنجره های سیستم باقی بماند. این برای اکثر برنامه ها کافی است.
با این حال، در برخی موارد، ممکن است نیاز داشته باشید که بالشتک پیشفرض را تغییر دهید تا طرحبندی مورد نظر را برای برنامه خود دریافت کنید. برای دستکاری مستقیم نحوه نمایش محتوای خود نسبت به نوارهای سیستم (که فضایی به نام "insets Content" پنجره را اشغال می کنند)، fitSystemWindows(Rect insets)
را نادیده بگیرید. متد fitSystemWindows()
توسط سلسله مراتب view زمانی فراخوانی می شود که ورودی های محتوای یک پنجره تغییر کرده باشد تا به پنجره اجازه دهد محتوای خود را مطابق با آن تنظیم کند. با نادیده گرفتن این روش، میتوانید ورودیها (و از این رو طرحبندی برنامهتان) را هر طور که میخواهید مدیریت کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و 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 status bar\n\nThis lesson describes how to hide the status bar on different versions of\nAndroid. Hiding the status bar (and optionally, the navigation bar) lets the\ncontent use more of the display space, thereby providing a more immersive user experience.\n\n\nFigure 1 shows an app with a visible status bar:\n\n**Figure 1.** Visible status bar.\n\n\nFigure 2 shows an app with a hidden status bar. Note that the action bar is hidden too.\nYou should never show the action bar without the status bar.\n\n**Figure 2.** Hidden status bar.\n\nHide the Status Bar on Android 4.0 and Lower\n--------------------------------------------\n\nYou can hide the status bar on Android 4.0 (API level 14) and lower by setting\n[WindowManager](/reference/android/view/WindowManager) flags. You can do this programmatically or by\nsetting an activity theme in your app's manifest file. Setting an activity theme in your app's\nmanifest file is the preferred approach if the status bar should always remain\nhidden in your app (though strictly speaking, you could programmatically override the\ntheme if you wanted to). For example: \n\n```xml\n\u003capplication\n ...\n android:theme=\"@android:style/Theme.Holo.NoActionBar.Fullscreen\" \u003e\n ...\n\u003c/application\u003e\n```\n\nThe advantages of using an activity theme are as follows:\n\n- It's easier to maintain and less error-prone than setting a flag programmatically.\n- It results in smoother UI transitions, because the system has the information it needs to render your UI before instantiating your app's main activity.\n\n\nAlternatively, you can programmatically set [WindowManager](/reference/android/view/WindowManager) flags.\nThis approach makes it easier to hide and show the status bar as the user interacts with\nyour app: \n\n### Kotlin\n\n```kotlin\nclass MainActivity : Activity() {\n\n override fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n // If the Android version is lower than Jellybean, use this call to hide\n // the status bar.\n if (Build.VERSION.SDK_INT \u003c 16) {\n window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\n WindowManager.LayoutParams.FLAG_FULLSCREEN)\n }\n setContentView(R.layout.activity_main)\n }\n ...\n}\n```\n\n### Java\n\n```java\npublic class MainActivity extends Activity {\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n // If the Android version is lower than Jellybean, use this call to hide\n // the status bar.\n if (Build.VERSION.SDK_INT \u003c 16) {\n getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\n WindowManager.LayoutParams.FLAG_FULLSCREEN);\n }\n setContentView(R.layout.activity_main);\n }\n ...\n}\n```\n\nWhen you set [WindowManager](/reference/android/view/WindowManager) flags (whether through an activity theme or\nprogrammatically), the flags remain in effect unless your app clears them.\n\nYou can use\n[FLAG_LAYOUT_IN_SCREEN](/reference/android/view/WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN)\nto set your activity layout to use the same screen area that's available when you've enabled\n[FLAG_FULLSCREEN](/reference/android/view/WindowManager.LayoutParams#FLAG_FULLSCREEN). This prevents your\ncontent from resizing when the status bar hides and shows.\n\nHide the Status Bar on Android 4.1 and Higher\n---------------------------------------------\n\nYou can hide the status bar on Android 4.1 (API level 16) and higher by\nusing [setSystemUiVisibility()](/reference/android/view/View#setSystemUiVisibility(int)).\n[setSystemUiVisibility()](/reference/android/view/View#setSystemUiVisibility(int)) sets UI flags at\nthe individual view level; these settings are aggregated to the window level. Using\n[setSystemUiVisibility()](/reference/android/view/View#setSystemUiVisibility(int)) to set UI flags\ngives you more granular control over the system bars than using\n[WindowManager](/reference/android/view/WindowManager) flags. This snippet hides the status bar: \n\n### Kotlin\n\n```kotlin\n// Hide the status bar.\nwindow.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN\n// Remember that you should never show the action bar if the\n// status bar is hidden, so hide that too if necessary.\nactionBar?.hide()\n```\n\n### Java\n\n```java\nView decorView = getWindow().getDecorView();\n// Hide the status bar.\nint uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;\ndecorView.setSystemUiVisibility(uiOptions);\n// Remember that you should never show the action bar if the\n// status bar is hidden, so hide that too if necessary.\nActionBar actionBar = getActionBar();\nactionBar.hide();\n```\n\nNote the following:\n\n- Once UI flags have been cleared (for example, by navigating away from the activity), 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\n\u003cbr /\u003e\n\nMake Content Appear Behind the Status Bar\n-----------------------------------------\n\nOn Android 4.1 and higher, you can set your application's content to appear behind\nthe status bar, so that the content doesn't resize as the status bar hides and shows.\nTo do this, use\n[SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN](/reference/android/view/View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN).\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 (for example, the built-in controls in a Maps application) don't end up\ngetting covered by system bars. This could make your app unusable. In most cases you can\nhandle this by adding the `android:fitsSystemWindows` attribute to your XML layout file, set to\n`true`. This adjusts the padding of the parent [ViewGroup](/reference/android/view/ViewGroup)\nto leave space for the system windows. This is sufficient for most applications.\n\nIn some cases, however, you may need to modify the default padding to get the desired\nlayout for your app. To directly manipulate how your\ncontent lays out relative to the system bars (which occupy a space known as the window's\n\"content insets\"), override [fitSystemWindows(Rect insets)](/reference/android/view/View#fitSystemWindows(android.graphics.Rect)).\nThe [fitSystemWindows()](/reference/android/view/View#fitSystemWindows(android.graphics.Rect)) method is called by the\nview hierarchy when the content insets for a window have changed, to allow the window to\nadjust its content accordingly. By overriding this method you can handle the\ninsets (and hence your app's layout) however you want."]]