ステータスバーを非表示にする
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このレッスンでは、
Android。ステータスバー(およびオプションでナビゲーション バー)を非表示にすると、
コンテンツの表示スペースが広くなるため、没入感のあるユーザー エクスペリエンスを実現できます。
ステータスバーが表示されたアプリを図 1 に示します。
図 1. 表示状態のステータスバー
ステータスバーを非表示にした状態のアプリを図 2 に示します。アクションバーも非表示になっています。
ステータスバーなしではアクションバーを表示しないでください。
図 2. 非表示状態のステータスバー
ステータスバーを非表示にする(Android 4.0 以前)
Android 4.0(API レベル 14)以前では、
WindowManager
フラグ。これは、プログラムで行うことも、
アプリのマニフェスト ファイルでアクティビティ テーマを設定する。アプリのアクティビティ テーマを設定する
ステータスバーを常に表示しておく必要がある場合は、マニフェスト ファイルを使用することをおすすめします。
(厳密に言えば、モジュールをプログラムでオーバーライドすることも、
できます。例:
<application
...
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
アクティビティ テーマを使用した場合、次のようなメリットがあります。
- プログラムでフラグをセットするよりも、メンテナンスが簡単で、エラーを低減することができます。
- システムに必要な情報があるため、UI の遷移がより滑らかになります。
を使用して UI をレンダリングしてから、アプリのメイン アクティビティをインスタンス化してください。
または、WindowManager
フラグをプログラムで設定することもできます。
このアプローチにより、ユーザーが操作する際にステータスバーの非表示 / 表示が簡単になります。
必要があります。
Kotlin
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)
}
...
}
Java
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
。これにより
ステータスバーの表示 / 非表示を切り替えたときにコンテンツのサイズ変更を防ぐことができます。
ステータスバーを非表示にする(Android 4.1 以降)
Android 4.1(API レベル 16)以降では、
setSystemUiVisibility()
を使用します。
setSystemUiVisibility()
は UI フラグを次の値に設定:
個々のビューレベルこれらの設定はウィンドウ レベルで集計されます。使用
setSystemUiVisibility()
: UI フラグを設定する
使用するよりも、システムバーをきめ細かく制御できます。
WindowManager
フラグ。ステータスバーを非表示にするスニペットを以下に示します。
Kotlin
// 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()
Java
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();
次の点にご注意ください。
コンテンツをステータスバーの背後に表示する
Android 4.1 以降では、アプリのコンテンツを背景に
ステータスバーの表示 / 非表示を切り替えてもコンテンツのサイズを変更せずに、
これを行うには、
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
。
また、kubectl の
SYSTEM_UI_FLAG_LAYOUT_STABLE
: アプリが
作成します。
このアプローチを採用する場合、ユーザーの責任において、
アプリの UI(たとえば、マップアプリの組み込みのコントロール)の
システムバーに埋もれてしまいがちですこのような部分が覆われると、アプリが使用できなくなる可能性があります。ほとんどの場合、
これに対処するには、XML レイアウト ファイルに android:fitsSystemWindows
属性を追加して、
true
。親 ViewGroup
のパディングを調整します。
システム ウィンドウ用のスペースを残します。ほとんどのアプリにおいて、この対応で十分です。
ただし、場合によっては、デフォルトのパディングを調整して、
作成できますアカウントの
コンテンツの配置は、システムバー(ウィンドウと呼ばれる領域)を基準として
「コンテンツ インセット」など)を指定し、fitSystemWindows(Rect insets)
をオーバーライドします。
fitSystemWindows()
メソッドは、サービス プロバイダによって
ウィンドウのコンテンツ インセットが変更されたときにビュー階層を作成し、ウィンドウを
それに応じて内容を調整します。このメソッドをオーバーライドすることで、
インセット(つまりアプリのレイアウト)を自由にカスタマイズできます。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","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 UTC。"],[],[],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."]]