处理键盘输入
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
试试 Compose 方式
Jetpack Compose 是推荐用于 Android 的界面工具包。了解 Compose 中的触控和输入操作。
当界面中的文本字段获得焦点时,Android 系统会显示屏幕键盘(称为“软键盘输入法”)。为了提供最佳用户体验,您可以指定有关所需输入类型(例如电话号码或电子邮件地址)以及输入法行为方式(例如自动更正拼写错误)的特征。
除屏幕输入法之外,Android 还支持硬件键盘,因此,您还需要优化应用以支持连接的键盘。
以下文档将介绍上述内容以及更多相关知识。
课程
- 指定输入法类型
- 了解如何显示特定的软键盘输入法,例如针对电话号码、网址或其他格式设计的软键盘输入法。此外,您还可以了解如何指定特征(例如拼写建议行为)和操作按钮(例如完成或下一步)。
- 处理输入法可见性
- 了解如何指定在何时显示软键盘输入法,以及布局必须如何调整以适应缩小的屏幕空间。
- 支持键盘导航
- 了解如何验证用户是否可以使用键盘浏览应用,以及如何对导航顺序进行任何必要的更改。
- 处理键盘操作
- 了解如何直接响应键盘输入以执行用户操作。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Handle keyboard input\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn about touch and input in Compose. \n[Touch and input →](/develop/ui/compose/touch-input) \n\nThe Android system shows an on-screen keyboard---known as a\n*soft input method*---when a text field in your UI receives focus.\nTo provide the best user experience, you can specify characteristics\nabout the type of input you expect, such as a\nphone number or email address, and how the input method must behave, such as\nperforming autocorrect for spelling mistakes.\n\nIn addition to the on-screen input methods, Android supports hardware keyboards, so it's\nalso important to optimize your app to support attached keyboards.\n\nThese topics and more are discussed in the following documentation.\n\nLessons\n-------\n\n**[Specify the input method type](/develop/ui/views/touch-and-input/keyboard-input/style)**\n: Learn how to show certain soft input methods, such as those designed for phone numbers, web\n addresses, or other formats. Also, learn how to specify characteristics such\n as spelling suggestion behavior and action buttons such as **Done** or **Next**.\n\n**[Handle input method visibility](/develop/ui/views/touch-and-input/keyboard-input/visibility)**\n: Learn how to specify when to show the soft input method and how\n your layout must adjust to the reduced screen space.\n\n**[Support keyboard navigation](/develop/ui/views/touch-and-input/keyboard-input/navigation)**\n: Learn how to verify that users can navigate your app using a keyboard\n and how to make any necessary changes to the navigation order.\n\n**[Handle keyboard actions](/develop/ui/views/touch-and-input/keyboard-input/commands)**\n: Learn how to respond directly to keyboard input for user actions."]]