自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
双窗格自定义
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 12 引入了一种新的双窗格设计,左侧为静态 L0 菜单,右侧为内容窗格。此功能引入了许多新的自定义选项。本页详细介绍了这些功能,并说明了如何自定义偏好设置。
还原为单窗格
默认情况下,当应用窗口宽度大于或等于 1400dp 时,CarSettings 现在会显示双窗格视图,否则会显示单窗格视图。如需针对特定设备进行自定义,请使用运行时资源叠加层 (RRO) 找到必要的配置值:
值 |
说明 |
config_global_force_single_pane |
如果整个应用采用单窗格配置运行,请将此值设置为 true 。 |
config_homepage_fragment_class |
用于指定首页的起始 fragment。在双窗格中,此值用于内容窗格中的初始 fragment。在单窗格中,这应该是首页 fragment。 |
由于不同的 CarSettings activity 可以具有自定义 IA,因此提供了一个标头键映射,以简化自定义。在 AndroidManifest.xml
中,每个支持双窗格的 activity 的元数据中都有一个 TOP_LEVEL_HEADER_KEY
。此值指向 res/values/header_keys.xml
中指定的键,且该键已映射到起始 fragment 所在的顶级菜单项的偏好设置键。因此,如果更改某个 activity 的起始 fragment,或重新排列 IA 以使特定 fragment 处于不同的顶级偏好设置下,则 header_keys.xml
文件中的相关映射可以更新为指定正确的值。
自定义 activity 布局
BaseCarSettingsActivity
的布局位于 res/layout/car_setting_activity
和以下各个部分中:
值 |
说明 |
top_level_menu |
双窗格配置中显示的顶级菜单 fragment。此部分的宽度由 top_level_menu_width 指定。底盘基本布局(含工具栏)被包裹在这个视图中。 |
top_level_divider |
拆分两个窗格的垂直线,其宽度可以使用 top_level_divider_width 自定义。 |
fragment_container_wrapper |
内容窗格(或单窗格配置中的主窗格)的封装容器布局。底盘基本布局(含工具栏)被包裹在这个视图中。 |
settings_focus_parking_view |
FocusParkingView 的自定义实现,用于在需要时保持旋转焦点。 |
fragment_container |
主内容容器。内容 fragment 将其用作目标布局。 |
restricted_message |
要在 BaseFragment 的实例上显示的用户体验受限的阻隔视图。 |

图 1. 双窗格布局
顶层偏好设置
顶层偏好设置是一类自定义 CarUiPreferences,具有略微修改的布局,用于更改偏好设置高度和背景形状。您可以通过多种不同的方式自定义这些偏好设置的外观:
值 |
说明 |
res/layout/top_level_preference.xml |
叠加整个偏好设置布局。 |
top_level_preference_min_height |
顶级偏好设置的最小高度。偏好设置可能会高于此值,具体取决于内容(例如,存在字幕的情况)。 |
top_level_preference_corner_radius |
圆角半径。 |
top_level_preference_background |
顶级偏好设置当前未突出显示时的背景。 |
top_level_preference_highlight |
顶层偏好设置突出显示时的背景。 |
顶层图标
图 2 说明了顶层图标现在如何由彩色背景形状中的矢量图标组成。此形状当前配置为支持椭圆形或矩形。默认情况下,形状设置为椭圆形。
如需更改默认设置,请修改 config_top_level_icon_shape
中的值(0 表示矩形,1 表示椭圆形)。这些图标是使用 top_level_foreground_icon_inset
从背景形状中嵌入前景图标来创建的。每个顶级图标都有一个在 res/values/colors.xml
中指定的前景颜色,以及一个在 res/color
文件夹中指定的背景颜色。
如需创建自定义外观,您可以替换所有颜色值。

图 2. 顶层偏好设置组件
属于 config_top_level_injection_categories
指定类别的注入偏好设置的图标也被视为顶层图标。提供的图标按与其他所有顶级图标相同的值嵌入并采用相同的形状(请参阅上文)。不过,背景是通过按照这个顺序查看以下属性来确定的:
com.android.settings.bg.argb
来自注入应用的元数据。
com.android.settings.bg.hint
来自注入应用的元数据。
top_level_injected_default_background
:在 res/values/colors.xml
中指定。
如需忽略注入应用数据并始终使用默认背景,请将 config_top_level_injection_background_always_use_default
设置为 true
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","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-07-27。"],[],[],null,["# Dual pane customization\n\nAndroid 12 introduces a *dual pane* design, with a static L0 menu on the left and\na content pane on the right. This feature introduces many new customization options. This page\ndetails those features and explains how you can customize your own preferences.\n\nRevert to single pane\n---------------------\n\nBy default, CarSettings now displays the dual pane view when the app window is\ngreater than or equal to 1400dp in width and the single pane view otherwise. To customize\nthis for a specific device, use a runtime resource overlay (RRO) to target the necessary\nconfiguration values:\n\n| Value | Description |\n|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `config_global_force_single_pane` | Set to `true` if the entire app is to run in single-pane configuration. |\n| `config_homepage_fragment_class` | Specifies the starting fragment for the homepage. In dual pane, this is used for the initial fragment in the content pane. In single-pane, this should be the homepage fragment. |\n\nHeader keys\n-----------\n\nBecause different CarSettings activities can have a customized IA, a header key mapping\nis provided to simplify customizations. In `AndroidManifest.xml`, every activity\nthat supports dual pane has a `TOP_LEVEL_HEADER_KEY` specified in its metadata.\nThis value points to a key specified in `res/values/header_keys.xml`, which is\nmapped to the preference key of the top-level menu item that the starting fragment falls under.\nTherefore, if the starting fragment of an activity is changed or the IA is rearranged such\nthat a particular fragment falls under a different top-level preference, the relevant mapping(s)\nin the `header_keys.xml` file can be updated to specify the correct value.\n\nCustomize activity layout\n-------------------------\n\nThe layout for `BaseCarSettingsActivity` is located in\n`res/layout/car_setting_activity` and in these sections:\n\n| Value | Description |\n|-------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `top_level_menu` | Top-level menu fragment shown in dual pane configurations. Width of this section is specified by `top_level_menu_width`. A chassis base layout (with toolbar) is wrapped around this view. |\n| `top_level_divider` | Vertical line that splits the two panes and whose width you can customize with `top_level_divider_width`. |\n| `fragment_container_wrapper` | Wrapper layout for the content pane (or the main pane in a singlepane configuration). A chassis baselayout (with toolbar) is wrapped around this view. |\n| `settings_focus_parking_view` | Custom implementation of `FocusParkingView` to hold rotary focus when needed. |\n| `fragment_container` | Main content container. Content fragments use this as the target layout. |\n| `restricted_message` | UX-restricted blocking view to be shown on instances of `BaseFragment`. |\n\n**Figure 1.** Dual pane layout\n\nTop-level preferences\n---------------------\n\nTop-level preferences are custom CarUiPreferences with a slightly modified layout to change\nthe preference height and background shape. There are many different ways to customize the look\nof these preferences:\n\n| Value | Description |\n|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|\n| `res/layout/top_level_preference.xml` | Overlay the *entire* preference layout. |\n| `top_level_preference_min_height` | Minimum height of the top-level preference. Depending on content (for example, a subtitle is present), preferences may be taller than this value. |\n| `top_level_preference_corner_radius` | Radius of the corner rounding. |\n| `top_level_preference_background` | Background of the top-level preferences when not currently highlighted. |\n| `top_level_preference_highlight` | Background of top-level preferences when highlighted. |\n\nTop-level icons\n---------------\n\nFigure 2 illustrates how the top-level icons now consist of a vector icon inside a colored\nbackground shape. This shape is currently configured to support either an oval a rectangular\nshape. By default, shape is set to oval.\n\nTo change the default, modify the value in `config_top_level_icon_shape`\n(where 0 is rectangle and 1 is oval). The icons are created by insetting the foreground icon by\n`top_level_foreground_icon_inset` from the background shape. Each top-level icon has\na foreground color specified in `res/values/colors.xml` and a background color\nspecified in the `res/color` folder.\n\nTo create a customized appearance, you can override all color values.\n\n**Figure 2.** Top-level preference components\n\nIcons for injected preferences that fall into the categories specified by\n`config_top_level_injection_categories` are also treated as top-level icons.\nThe provided icons are inset by the same value and into the same shape as specified for\nall other top-level icons (see above). However, the background is determined by looking\nat the following attributes in this order:\n\n1. `com.android.settings.bg.argb` Meta data from the injecting app.\n2. `com.android.settings.bg.hint` Meta data from the injecting app.\n3. `top_level_injected_default_background` Specified in `res/values/colors.xml`.\n\nTo ignore the injecting app data and always use the default background, set\n`config_top_level_injection_background_always_use_default` to `true`."]]