> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Color Palette

> Color Palette

# Color Palette

可在布局中引用的一组可重用颜色。

## 属性

`default` - *object*，*可选*。一组[十六进制颜色](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-hexcolor)定义，可使用[颜色引用](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-colorreference)引用。

`highContrast` - *object*，*可选*。一组[十六进制颜色](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-hexcolor)定义，可使用[颜色引用](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-colorreference)引用。启用[高对比度模式](https://devdocs.xbox.com/zh-CN/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-tak-high-contrast-mode.md)时，覆盖 `default` 中的定义。

## 示例

```JSON theme={null}
{
  "$schema": "https://raw.githubusercontent.com/microsoft/xbox-game-streaming-tools/main/touch-adaptation-kit/schemas/layout/4.0/layout.json",
  "styles": {
    "colors": {
      "default": {
        "myColor1": "#ff0000ff",
        "myColor2": "#00ff00ff",
        "system_contentPrimary": "#0000ffff"
      },
      "highContrast": {
        "myColor1": "#00ff00ff",
        "system_contrastPrimary": "#0000ffaa"
      }
    }
  },
  "content": {
    "left": {
      "inner": [
        {
          "type": "directionalPad",
          "styles": {
            "idle": {
              "background": {
                "type": "color",
                "value": "colors/myColor1"
              }
            }
          }
        }
      ]
    },
    "right": {
      "inner": [
          {
              "type": "button",
              "action": "gamepadY"
          },
          {
              "type": "button",
              "action": "gamepadB"
          },
          {
              "type": "button",
              "action": "gamepadA",
              "styles": {
                "idle": {
                  "background": {
                    "type": "color",
                    "value": "colors/myColor2"
                  }
                }
              }
          },
          {
              "type": "button",
              "action": "gamepadX"
          }
      ]
    }
  }
}
```

上述布局在高对比度模式**禁用**时：

![禁用高对比度模式的颜色调色板触控布局](https://mintcdn.com/microsoft-4404708b/-_0FrcE2bDxzGxv-/images/gdk/reference/game-streaming-tak-color-palette-reference-hc-disabled.png?fit=max\&auto=format\&n=-_0FrcE2bDxzGxv-\&q=85\&s=dba732004eecd1db8fc9a608c31248cd)

在高对比度模式**启用**时：

![启用高对比度模式的颜色调色板触控布局](https://mintcdn.com/microsoft-4404708b/-_0FrcE2bDxzGxv-/images/gdk/reference/game-streaming-tak-color-palette-reference-hc-enabled.png?fit=max\&auto=format\&n=-_0FrcE2bDxzGxv-\&q=85\&s=fff468e0eba734e9edec6527e7584262)

## 备注

上述[示例](#sample)包含覆盖[系统颜色](#system-colors)的颜色定义（例如 `system_contentPrimary`、`system_accentPrimary` 等）以及自定义颜色定义（`myColor1`、`myColor2`）。控件在设置样式时**隐式**采样系统颜色，这意味着任何覆盖将影响所有控件的全局样式（除非某控件在自定义 `styles` 块中有自己的覆盖）。自定义颜色必须使用[颜色引用](https://devdocs.xbox.com/zh-CN/reference/system/touchadaptationkit/types/game-streaming-touch-colorreference)（例如 `colors/myColor1`）**显式**引用。此外，自定义颜色定义**不能**使用保留的 `system_` 前缀，因为该前缀保留给系统颜色。

颜色定义在 `default` 和 `highContrast` 对象中声明，分别在[高对比度模式](https://devdocs.xbox.com/zh-CN/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-tak-high-contrast-mode.md)禁用或启用时激活。禁用高对比度模式时，颜色从 `default` 采样。启用时，颜色首先从 `highContrast` 采样，若无定义则回退到 `default`。如果 `default` 中未提供系统颜色的覆盖，则使用系统默认值；而自定义颜色**必须**在 `default` 中定义。下表概述了上述颜色定义如何根据高对比度 (HC) 模式是否启用进行解析：

| 颜色定义 | 禁用 HC 模式 | 启用 HC 模式 |
| :- | - | - |
| myColor1 | `#ff0000ff` | `#00ff00ff` |
| myColor2 | `#00ff00ff` | `#00ff00ff` |
| system\_contentPrimary | `#0000ffff` | `#0000ffff` |
| system\_contrastPrimary | 系统默认值 | `#0000ffaa` |

## 系统颜色

下表总结了 Touch Adaptation Kit 中的系统颜色列表、它们如何用于设置控件样式，以及高对比度 (HC) 模式禁用/启用时的系统默认值。

| 系统颜色 | 描述 | 禁用 HC 模式 | 启用 HC 模式 |
| :- | :- | :- | :- |
| system\_contentPrimary | 用于为中间描边、图标着色和方向键渐变等组件设置样式的颜色。 | `#ffffffff` | `#ffffffff` |
| system\_contentSecondary | 用于为背景和填充等组件设置样式的颜色。 | `#ffffff1a` | `#ffffffff` |
| system\_contrastPrimary | 用于为内/外描边和图案图像底板等对比组件设置样式的颜色。 | `#00000000` | `#000000bf` |
| system\_contrastSecondary | 用于为触控板描边等对比组件设置样式的颜色。 | `#00000000` | `#ffffffff` |
| system\_actionColorDefault | 用于为 `action` 字段设置为非 gamepad 操作的控件上的组件设置样式的颜色。 | `#ffffffff` | `#ffffffe6` |
| system\_actionColorA | 用于为 `action` 字段设置为 `gamepadA` 的控件上的组件设置样式的颜色。 | `#7eb902ff` | `#ffffffe6` |
| system\_actionColorB | 用于为 `action` 字段设置为 `gamepadB` 的控件上的组件设置样式的颜色。 | `#f25127ff` | `#ffffffe6` |
| system\_actionColorX | 用于为 `action` 字段设置为 `gamepadX` 的控件上的组件设置样式的颜色。 | `#00a2eeff` | `#ffffffe6` |
| system\_actionColorY | 用于为 `action` 字段设置为 `gamepadY` 的控件上的组件设置样式的颜色。 | `#ffb807ff` | `#ffffffe6` |
| system\_accentPrimary | 用于为人体工程学编辑内轮等组件设置样式的颜色。 | `#8cc08cff` | `#8cc08cff` |
| system\_accentSecondary | 用于为人体工程学编辑外轮等组件设置样式的颜色。 | `#61ab61ff` | `#61ab61ff` |

有关最新列表，请参阅[最新架构](https://github.com/microsoft/xbox-game-streaming-tools/blob/main/touch-adaptation-kit/schemas/layout/v4.0/layout.json)中以 `_SystemColor` 为前缀的定义。

## 另请参阅

[Touch Adaptation Kit 参考](https://devdocs.xbox.com/zh-CN/build/core-features/common/game-streaming/game-streaming-touch-touch-adaptation-kit-overview.md)\
[触控适配布局的高对比度模式](https://devdocs.xbox.com/zh-CN/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-tak-high-contrast-mode.md)


## Related topics

- [Touch Adaptation Kit](https://devdocs.xbox.com/reference/system/touchadaptationkit/touchadaptationkit-reference.md)
- [High contrast mode for Touch Adaptation Layouts](https://devdocs.xbox.com/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-tak-high-contrast-mode.md)
- [Touch Adaptation Kit Editor: Customize Preview](https://devdocs.xbox.com/build/core-features/common/game-streaming/tak-editor/game-streaming-tak-editor-customize-preview.md)
- [Accessibility metadata](https://devdocs.xbox.com/publishing/game-publishing/concepts/metadata-accessibility.md)
- [Éditeur du Touch Adaptation Kit : personnaliser l'aperçu](https://devdocs.xbox.com/fr/build/core-features/common/game-streaming/tak-editor/game-streaming-tak-editor-customize-preview.md)
