Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

AndroidWindowInsets

class in UnityEngine.Android

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Provides control over the windows that generate insets.

These windows represent the system UI elements for system bars, such as the status and navigation bars. Use this class to determine the current state of the system bars, control their visibility and behavior at runtime, allowing your application to make full use of the device screen space.

Additional resources: About window insets (Android)

using UnityEngine;
using UnityEngine.Android;

public class AndroidInsets : MonoBehaviour { public string GetInsetsVisibility(AndroidWindowInsets.Type type) { if (AndroidApplication.currentWindowInsets == null) return "Unknown"; return AndroidApplication.currentWindowInsets.IsVisible(type) ? "Visible" : "Hidden"; }

public void OnGUI() { var options = new[] { GUILayout.Height(100), GUILayout.ExpandWidth(true) }; GUILayout.Space(100); GUILayout.Label($"Status Bars: {GetInsetsVisibility(AndroidWindowInsets.Type.StatusBars)}", options); GUILayout.Label($"Navigation Bars: {GetInsetsVisibility(AndroidWindowInsets.Type.NavigationBars)}", options);

var insets = AndroidApplication.currentWindowInsets; GUILayout.BeginHorizontal(GUILayout.Width(Screen.width)); if (GUILayout.Button("Show Status Bars", options)) insets.Show(AndroidWindowInsets.Type.StatusBars); if (GUILayout.Button("Hide Status Bars", options)) insets.Hide(AndroidWindowInsets.Type.StatusBars); GUILayout.EndHorizontal();

GUILayout.BeginHorizontal(GUILayout.Width(Screen.width)); if (GUILayout.Button("Show Navigation Bars", options)) insets.Show(AndroidWindowInsets.Type.NavigationBars); if (GUILayout.Button("Hide Navigation Bars", options)) insets.Hide(AndroidWindowInsets.Type.NavigationBars); GUILayout.EndHorizontal();

GUILayout.Label($"System Bars Behavior: {insets.GetSystemBarsBehavior()}", options); GUILayout.BeginHorizontal(GUILayout.Width(Screen.width)); if (GUILayout.Button("Default", options)) insets.SetSystemBarsBehavior(AndroidWindowInsets.SystemBarsBehavior.Default); if (GUILayout.Button("ShowTransientBarsBySwipe", options)) insets.SetSystemBarsBehavior(AndroidWindowInsets.SystemBarsBehavior.ShowTransientBarsBySwipe); GUILayout.EndHorizontal(); } }

Public Methods

Method Description
GetSystemBarsBehaviorRetrieves the configured behavior of system bars, such as status and navigation bars.
HideHides a set of windows that generate insets.
IsVisibleIndicates whether a set of windows that might generate insets is currently visible on screen, regardless of whether they overlap with your application window.
SetSystemBarsBehaviorControls the behavior of system bars.
ShowDisplays a set of windows that generate insets on screen.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961