自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
支持多窗口模式
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在 Android 7.0 及更高版本中,设备可以使用多窗口模式同时显示多个应用。Android 支持三种多窗口模式配置:
-
分屏是默认的多窗口模式实现,可为用户提供两个 activity 窗格来放置应用。
-
自由窗口允许用户动态调整 activity 窗格大小,并在屏幕上显示两个以上的应用。
-
画中画 (PIP) 允许 Android 设备在用户与其他应用互动时在小窗口中播放视频内容。
实现
Android 7.0 及更高版本中会默认启用多窗口模式支持。如需停用该功能,请在设备的 config.xml 文件中将 config_supportsMultiWindow
标志设置为 false
。
所有低内存设备(声明 ActivityManager.isLowRam()
的设备)默认停用多窗口模式。低内存设备会忽略 config_supportsMultiWindow
标志的值。
分屏
多窗口模式的默认体验是分屏模式,在这种模式下,系统会从设备中间以横向或纵向方式划分系统界面。用户可以根据设备的屏幕方向左右或上下拖动分界线来调整窗口大小。
启用分屏后,设备制造商可以选择是否启用自由窗口或“画中画”模式。
在 Android 8.0 及更高版本中,在用户点按主屏幕时,系统会压缩启动器的大小以改进分屏效果。如需了解实现方面的详细信息,请参阅分屏交互。
通过 config_supportsMultiWindow
标志启用多窗口模式后,设备制造商可以允许启用自由窗口。此模式在较大的设备(例如平板电脑)上最为有用。
如需支持自由窗口模式,请启用 /android/frameworks/base/core/java/android/content/pm/PackageManager.java
中的 PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT
系统功能,并在 config.xml.
中将 config_freeformWindowManagement
设置为 true
。
<bool name="config_freeformWindowManagement">true</bool>
画中画
通过 config_supportsMultiWindow
标志启用多窗口模式后,设备制造商可以支持画中画功能,以便用户在浏览其他 activity 的同时能够观看视频。虽然此功能针对的是 Android 电视设备,但其他设备类型也可以支持此功能。
如需支持画中画功能,请在 /android/frameworks/base/core/java/android/content/pm/PackageManager.java
中启用 PackageManager#FEATURE_PICTURE_IN_PICTURE
系统功能。
如需了解 Android 8.0 及更高版本设备的画中画实现详情,请参阅画中画页面。
系统界面
如多窗口模式开发者文档中所述,该功能支持所有标准系统界面。
应用
如需在预加载应用中提供多窗口模式支持,请参阅 Android 开发者文档。
验证
如需验证多窗口模式的实现情况,请运行相关 CTS 测试,并按照多窗口模式测试说明进行操作。
对于 Android 7.0,相关测试位于
/platform/cts/hostsidetests/services/activitymanager/src/android/server/cts
。
在 Android 8.0 及更高版本中,相关测试位于
/platform/cts/tests/framework/base/activitymanager/src/android/server/am
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-04。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-04-04。"],[],[],null,["# Support multi-window\n\nIn Android 7.0 and higher, devices can display multiple apps\nsimultaneously using multi-window. Android supports three\nmulti-window configurations:\n\n- **Freeform** allows users to dynamically resize the activity panes and have more than two apps visible on their screen.\n- **Split-screen** is the default multi-window implementation, which provides two activity panes where users can place apps.\n- **Picture-in-picture (PIP)** allows Android devices to play video content in a small window while the user interacts with other apps.\n\nImplementation\n--------------\n\n\nMulti-window support is enabled by default in Android 7.0 and higher.\nTo disable it, set the `config_supportsMultiWindow` flag to\n`false` in your device's\n[config.xml](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/values/config.xml) file.\n\n\nMulti-window is disabled by default on all low-RAM devices (devices that\ndeclare `ActivityManager.isLowRam()`). Low-RAM devices\nignore the value of the `config_supportsMultiWindow` flag.\n\n### Freeform\n\n\nAfter enabling multi-window mode with the\n`config_supportsMultiWindow` flag, device manufacturers can\nallow freeform windowing. This mode is most useful on larger devices,\nsuch as tablets.\n\n\nTo support freeform mode, enable the\n`PackageManager#FEATURE_FREEFORM_WINDOW_MANAGEMENT` system\nfeature in\n[/android/frameworks/base/core/java/android/content/pm/PackageManager.java](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/java/android/content/pm/PackageManager.java)\nand set `config_freeformWindowManagement` to `true` in\n[config.xml](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/values/config.xml)`.` \n\n```\n \u003cbool name=\"config_freeformWindowManagement\"\u003etrue\u003c/bool\u003e\n \n```\n\n\nIn Android 16, OEMs can support desktop windowing on their device for a\nfreeform multi-window configuration using [Enable desktop windowing](/docs/core/display/multi-window#enable-desktop-windowing).\n\n#### Enable desktop windowing\n\n\nFollow these steps to enable desktop windowing on your device:\n\n- Make sure your device supports [freeform](/docs/core/display/multi-window#freeform) windowing.\n- Set the config overlay flag `config_isDesktopModeSupported` flag to `true` in [`config.xml`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/values/config.xml): \n\n ```\n \u003cbool name=\"config_isDesktopModeSupported\"\u003etrue\u003c/bool\u003e\n \n ```\n- To enable freeform windowing on the internal display of your device, set the config overlay flag `config_canInternalDisplayHostDesktops` to `true` in `config.xml`. This flag is ignored if `config_isDesktopModeSupported` is `false`: \n\n ```\n \u003cbool name=\"config_canInternalDisplayHostDesktops\"\u003etrue\u003c/bool\u003e\n \n ```\n\n##### Enable task limits\n\n\nFollow these steps to configure the maximum number of tasks supported in desktop\nwindowing:\n\n1. [Enable desktop windowing](#enable-desktop-windowing).\n2. Set the config overlay flag `config_maxDesktopWindowingActiveTasks` in [`config.xml`](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/values/config.xml) to the maximum number of supported tasks. To support an unlimited number of tasks, set the flag to the default value of `0`: \n\n ```\n \u003cbool name=\"config_maxDesktopWindowingActiveTasks\"\u003e4\u003c/integer\u003e\n \n ```\n\n### Split-screen\n\n\nMulti-window's default experience is split-screen mode, where the System\nUI is divided down the middle of the device in portrait or landscape.\nUsers can resize the window by dragging the dividing line side to side\nor top to bottom, depending on the device orientation.\n\n\nAfter enabling split-screen, device manufacturers can choose to enable\nfreeform or PIP.\n\n\nAndroid 8.0 and higher improves split-screen by compressing the launcher\nwhen the user taps **Home** . For implementation details, see\n[Split-screen interactions](/docs/core/display/split-screen).\n\n### Picture-in-picture\n\n\nAfter enabling multi-window mode with the\n`config_supportsMultiWindow` flag, device manufacturers can\nsupport\n[picture-in-picture](https://developer.android.com/training/tv/playback/picture-in-picture.html), which allows users to watch\nvideo while browsing other activities. While this feature is targeted at\nAndroid Television devices, other device types may support this feature.\n\n\nTo support PIP, enable the\n`PackageManager#FEATURE_PICTURE_IN_PICTURE` system feature in\n[/android/frameworks/base/core/java/android/content/pm/PackageManager.java](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/java/android/content/pm/PackageManager.java).\n\n\nFor more PIP implementation details for devices running Android 8.0 and\nhigher,see the [Picture-in-picture](/docs/core/display/pip)\npage.\n\n### System UI\n\n\nSupport all standard System UIs according to\n[Multi-window developer documentation](https://developer.android.com/guide/topics/ui/multi-window.html#testing).\n\n### Apps\n\n\nTo support multi-window mode for preloaded apps, consult the\n[Android developer documentation](https://developer.android.com/guide/topics/ui/multi-window.html).\n\nValidation\n----------\n\n\nTo validate your implementation of multi-window, run the related CTS\ntests and follow the\n[testing instructions for multi-window](https://developer.android.com/guide/topics/ui/multi-window.html#testing).\n\n| Android version | CTS test |\n|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 7.0 | [/platform/cts/hostsidetests/services/activitymanager/src/android/server/cts](https://android.googlesource.com/platform/cts/+/refs/heads/nougat-cts-release/hostsidetests/services/activitymanager/src/android/server/cts) |\n| 8.0 | [/platform/cts/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts](https://android.googlesource.com/platform/cts/+/refs/heads/oreo-cts-release/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts) |\n| 9.0 | [/platform/cts/tests/framework/base/activitymanager/src/android/server/am](https://android.googlesource.com/platform/cts/+/refs/heads/pie-cts-release/tests/framework/base/activitymanager/src/android/server/am) |\n| 10.0 and above | [/platform/cts/tests/framework/base/windowmanager/src/android/server/wm](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/framework/base/windowmanager/src/android/server/wm) |"]]