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(); } }
| Method | Description |
|---|---|
| GetSystemBarsBehavior | Retrieves the configured behavior of system bars, such as status and navigation bars. |
| Hide | Hides a set of windows that generate insets. |
| IsVisible | Indicates whether a set of windows that might generate insets is currently visible on screen, regardless of whether they overlap with your application window. |
| SetSystemBarsBehavior | Controls the behavior of system bars. |
| Show | Displays a set of windows that generate insets on screen. |