Skip to main content

Button

一个基本的按钮组件,应该在任何平台上都能很好地渲染。支持最低程度的定制。

¥A basic button component that should render nicely on any platform. Supports a minimal level of customization.

如果此按钮不适合你的应用,你可以使用 Pressable 构建你自己的按钮。如需灵感,请查看 Button 组件的源代码

¥If this button doesn't look right for your app, you can build your own button using Pressable. For inspiration, look at the source code for the Button component.

<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>

示例

¥Example


参考

¥Reference

属性

¥Props

当用户点击按钮时调用的处理程序。

¥Handler to be called when the user taps the button.

类型
({nativeEvent: PressEvent})

显示在按钮内的文本。在 Android 上,给定的标题将转换为大写形式。

¥Text to display inside the button. On Android the given title will be converted to the uppercased form.

类型
string

accessibilityLabel

为失明辅助功能显示的文本。

¥Text to display for blindness accessibility features.

类型
string

accessibilityLanguage
iOS

指示用户与元素交互时屏幕阅读器应使用哪种语言的值。它应该遵循 BCP 47 规范

¥A value indicating which language should be used by the screen reader when the user interacts with the element. It should follow the BCP 47 specification.

请参阅 iOS accessibilityLanguage 文档 了解更多信息。

¥See the iOS accessibilityLanguage doc for more information.

类型
string

accessibilityActions

辅助功能操作允许辅助技术以编程方式调用组件的操作。accessibilityActions 属性应包含操作对象的列表。每个操作对象应包含字段名称和标签。

¥Accessibility actions allow an assistive technology to programmatically invoke the actions of a component. The accessibilityActions property should contain a list of action objects. Each action object should contain the field name and label.

请参阅 无障碍指南 了解更多信息。

¥See the Accessibility guide for more information.

类型必需的
array

onAccessibilityAction

当用户执行辅助功能操作时调用。该函数的唯一参数是一个包含要执行的操作名称的事件。

¥Invoked when the user performs the accessibility actions. The only argument to this function is an event containing the name of the action to perform.

请参阅 无障碍指南 了解更多信息。

¥See the Accessibility guide for more information.

类型必需的
function

color

文本颜色 (iOS) 或按钮背景颜色 (Android)。

¥Color of the text (iOS), or background color of the button (Android).

类型默认
color

disabled

如果是 true,则禁用该组件的所有交互。

¥If true, disable all interactions for this component.

类型默认
boolfalse

hasTVPreferredFocus
电视

¥hasTVPreferredFocus

TV

电视首选焦点。

¥TV preferred focus.

类型默认
boolfalse

nextFocusDown
Android
电视

¥nextFocusDown

Android
TV

指定当用户向下导航时接收焦点的下一个视图。参见 安卓文档

¥Designates the next view to receive focus when the user navigates down. See the Android documentation.

类型
number

nextFocusForward
Android
电视

¥nextFocusForward

Android
TV

指定用户向前导航时接收焦点的下一个视图。参见 安卓文档

¥Designates the next view to receive focus when the user navigates forward. See the Android documentation.

类型
number

nextFocusLeft
Android
电视

¥nextFocusLeft

Android
TV

指定当用户向左导航时接收焦点的下一个视图。参见 安卓文档

¥Designates the next view to receive focus when the user navigates left. See the Android documentation.

类型
number

nextFocusRight
Android
电视

¥nextFocusRight

Android
TV

指定当用户向右导航时接收焦点的下一个视图。参见 安卓文档

¥Designates the next view to receive focus when the user navigates right. See the Android documentation.

类型
number

nextFocusUp
Android
电视

¥nextFocusUp

Android
TV

指定用户向上导航时接收焦点的下一个视图。参见 安卓文档

¥Designates the next view to receive focus when the user navigates up. See the Android documentation.

类型
number

testID

用于在端到端测试中定位此视图。

¥Used to locate this view in end-to-end tests.

类型
string

touchSoundDisabled
Android

如果是 true,则触摸时不播放系统声音。

¥If true, doesn't play system sound on touch.

类型默认
booleanfalse