This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
分段按钮
用于单选或多选的 Jetpack Compose 分段按钮组件。
分段按钮让应用用户可以从一组并排显示的小型选项中进行选择。它们对应官方 Jetpack Compose 分段按钮 API。
容器有两种类型:
SingleChoiceSegmentedButtonRow:一次只能选择一个按钮(类似单选按钮)。MultiChoiceSegmentedButtonRow:可以独立切换多个按钮(类似复选框)。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
单选分段按钮
当一次只能启用一个选项时,使用 SingleChoiceSegmentedButtonRow。每个 SegmentedButton 接受 selected 和 onClick 属性。
多选分段按钮
当多个选项可以独立切换时,使用 MultiChoiceSegmentedButtonRow。每个 SegmentedButton 接受 checked 和 onCheckedChange 属性。
自定义颜色
使用 SegmentedButton 上的 colors 属性,可自定义其在启用、未启用和禁用状态下的外观。
API
import { SingleChoiceSegmentedButtonRow, MultiChoiceSegmentedButtonRow, SegmentedButton, } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<MultiChoiceSegmentedButtonRowProps>
A row container for multi-choice SegmentedButton children.
Maps to Material 3 MultiChoiceSegmentedButtonRow.
Type: React.Element<SegmentedButtonProps>
A Material 3 segmented button. Must be used inside a SingleChoiceSegmentedButtonRow
or MultiChoiceSegmentedButtonRow.
booleanWhether the button is currently checked (used inside MultiChoiceSegmentedButtonRow).
(checked: boolean) => voidCallback that is called when the checked state changes (used inside MultiChoiceSegmentedButtonRow).
() => voidCallback that is called when the button is clicked (used inside SingleChoiceSegmentedButtonRow).
Type: React.Element<SingleChoiceSegmentedButtonRowProps>
A row container for single-choice SegmentedButton children.
Maps to Material 3 SingleChoiceSegmentedButtonRow.