Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
59598418
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
59598418
编写于
10月 11, 2022
作者:
L
luoying_ace
提交者:
Gitee
10月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textinput.md.
Signed-off-by:
N
luoying_ace
<
luoying19@huawei.com
>
上级
f7bbd935
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
63 deletion
+55
-63
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textinput.md
...n-dev/reference/arkui-ts/ts-basic-components-textinput.md
+55
-63
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textinput.md
浏览文件 @
59598418
# TextInput
可以输入单行文本并支持响应输入事件的
组件。
单行文本输入框
组件。
> **说明:**
>
...
...
@@ -20,7 +20,7 @@ TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: Te
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ----------------------- | ---------------------------------------- | ---- | --------------- |
| placeholder |
[
ResourceStr
](
ts-types.md#resourcestr
)
| 否 | 无输入时的提示文本。 |
| placeholder |
[
ResourceStr
](
ts-types.md#resourcestr
)
| 否 |
设置
无输入时的提示文本。 |
| text |
[
ResourceStr
](
ts-types.md#resourcestr
)
| 否 | 设置输入框当前的文本内容。 |
| controller
<sup>
8+
</sup>
|
[
TextInputController
](
#textinputcontroller8
)
| 否 | 设置TextInput控制器。 |
...
...
@@ -32,26 +32,26 @@ TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: Te
| 名称 | 参数类型 | 描述 |
| ------------------------ | ---------------------------------------- | ---------------------------------------- |
| type | InputType | 设置输入框类型。
<br/>
默认值:InputType.Normal |
| placeholderColor |
[
ResourceColor
](
ts-types.md#resourcecolor
)
| 设置placeholder颜色。|
| placeholderColor |
[
ResourceColor
](
ts-types.md#resourcecolor
)
| 设置placeholder
文本
颜色。|
| placeholderFont |
[
Font
](
ts-types.md#font
)
| 设置placeholder文本样式。 |
| enterKeyType | EnterKeyType | 设置输入法回车键类型。
<br/>
默认值:EnterKeyType.Done |
| caretColor |
[
ResourceColor
](
ts-types.md#resourcecolor
)
| 设置输入框光标颜色。 |
| maxLength | number | 设置文本的最大输入字符数。 |
| inputFilter
<sup>
8+
</sup>
| {
<br/>
value:
[ResourceStr](ts-types.md#resourcestr),
<br/>
error?:
(value:
string)
=
>
void
<br/>
} | 正则表达式,
满足表达式的输入允许显示,不满足正则表达式的输入被忽略。仅支持单个字符匹配,不支持字符串匹配。例如:^(?=.
\*\d
)(?=.
\*
[a-z])(?=.
\*
[A-Z]).{8,10}$,8到10位的强密码不支持过滤。
<br/>
-
value:设置正则表达式。
<br/>
-
error:正则匹配失败时,返回被忽略
的内容。 |
| copyOption
<sup>
9+
</sup>
|
[
CopyOptions
](
ts-appendix-enums.md#copyoptions9
)
| 设置文本是否可复制。 |
| showPasswordIcon
<sup>
9+
</sup>
| boolean | 密码输入模式时,
密码
框末尾的图标是否显示。
<br/>
默认值:true |
| style
<sup>
9+
</sup>
| TextInputStyle |
TextInput
风格。
<br/>
默认值:TextInputStyle.Default |
| textAlign
<sup>
9+
</sup>
|
[
TextAlign
](
ts-appendix-enums.md#textalign
)
| 设置
文本水平对齐
式。
<br/>
默认值:TextAlign.Start |
| inputFilter
<sup>
8+
</sup>
| {
<br/>
value:
[ResourceStr](ts-types.md#resourcestr),
<br/>
error?:
(value:
string)
=
>
void
<br/>
} | 正则表达式,
匹配表达式的输入允许显示,不匹配的输入将被过滤。目前仅支持单个字符匹配,不支持字符串匹配。
<br/>
-
value:设置正则表达式。
<br/>
-
error:正则匹配失败时,返回被过滤
的内容。 |
| copyOption
<sup>
9+
</sup>
|
[
CopyOptions
](
ts-appendix-enums.md#copyoptions9
)
| 设置
输入的
文本是否可复制。 |
| showPasswordIcon
<sup>
9+
</sup>
| boolean | 密码输入模式时,
输入
框末尾的图标是否显示。
<br/>
默认值:true |
| style
<sup>
9+
</sup>
| TextInputStyle |
设置输入框为默认风格或内联输入
风格。
<br/>
默认值:TextInputStyle.Default |
| textAlign
<sup>
9+
</sup>
|
[
TextAlign
](
ts-appendix-enums.md#textalign
)
| 设置
输入文本在输入框中的对齐方
式。
<br/>
默认值:TextAlign.Start |
## EnterKeyType枚举说明
| 名称 | 描述 |
| ------------------- | --------- |
| Go | 显示
Go文本
。 |
| Go | 显示
为前往样式
。 |
| Search | 显示为搜索样式。 |
| Send | 显示为发送样式。 |
| Next | 显示为下一个样式。 |
| Done |
标准
样式。 |
| Done |
显示为确认
样式。 |
## InputType枚举说明
...
...
@@ -59,7 +59,7 @@ TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: Te
| ------------------ | ------------- |
| Normal | 基本输入模式。
<br/>
支持输入数字、字母、下划线、空格、特殊字符。 |
| Password | 密码输入模式。 |
| Email |
e-mail
地址输入模式。 |
| Email |
邮箱
地址输入模式。 |
| Number | 纯数字输入模式。 |
| PhoneNumber
<sup>
9+
</sup>
| 电话号码输入模式。
<br/>
支持输入数字、+ 、-、
*
、#,长度不限。 |
...
...
@@ -67,20 +67,20 @@ TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: Te
| 名称 | 描述 |
| ------------------ | ------------- |
| Default | 默认风格,光标宽1.5vp,光标高度
和字体大小高度相关,字体越大光标越高。
|
| Inline
| 内联输入风格。文字选中时底板与输入框同高
。 |
| Default | 默认风格,光标宽1.5vp,光标高度
与文本选中底板高度和字体大小相关。
|
| Inline
| 内联输入风格。文本选中底板高度与输入框高度相同
。 |
## 事件
| 名称 | 功能描述 |
| ---------------------------------------- | ---------------------------------------- |
| onChange(callback:
(value:
string)
=
>
void) | 输入
发生变化时,触发
回调。 |
| onSubmit(callback:
(enterKey:
EnterKeyType)
=
>
void) |
回车键或者软键盘回车键触发该回调,参数为当前软键盘回车键
类型。 |
| onEditChanged(callback:
(isEditing:
boolean)
=
>
void)
<sup>
(deprecated)
</sup>
| 输入状态变化时,触发回调。
|
| onEditChange(callback:
(isEditing:
boolean)
=
>
void)
<sup>
8+
</sup>
| 输入状态变化时,触发
回调。
|
| onCopy
<sup>
8+
</sup>
(callback:(value:
string)
=
>
void) | 长按输入框内部区域弹出剪贴板后,点击剪切板复制按钮,触发回调。
<br/>
value:复制的文本内容。 |
| onCut
<sup>
8+
</sup>
(callback:(value:
string)
=
>
void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。
<br/>
value:剪切的文本内容。 |
| onPaste
<sup>
8+
</sup>
(callback:(value:
string)
=
>
void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。
<br/>
value:粘贴的文本内容。 |
| onChange(callback:
(value:
string)
=
>
void) | 输入
内容发生变化时,触发该
回调。 |
| onSubmit(callback:
(enterKey:
EnterKeyType)
=
>
void) |
按下输入法回车键触发该回调,返回值为当前输入法回车键的
类型。 |
| onEditChanged(callback:
(isEditing:
boolean)
=
>
void)
<sup>
(deprecated)
</sup>
| 输入状态变化时,触发该回调。从API 8开始,建议使用onEditChange。
|
| onEditChange(callback:
(isEditing:
boolean)
=
>
void)
<sup>
8+
</sup>
| 输入状态变化时,触发
该回调。isEditing为true表示正在输入。
|
| onCopy
<sup>
8+
</sup>
(callback:(value:
string)
=
>
void) | 长按输入框内部区域弹出剪贴板后,点击剪切板复制按钮,触发
该
回调。
<br/>
value:复制的文本内容。 |
| onCut
<sup>
8+
</sup>
(callback:(value:
string)
=
>
void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发
该
回调。
<br/>
value:剪切的文本内容。 |
| onPaste
<sup>
8+
</sup>
(callback:(value:
string)
=
>
void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发
该
回调。
<br/>
value:粘贴的文本内容。 |
## TextInputController<sup>8+</sup>
...
...
@@ -105,60 +105,52 @@ caretPosition(value: number): void
## 示例
### 单行文本输入
```
ts
// xxx.ets
@
Entry
@
Component
struct
TextInputExample1
{
@
State
text
:
string
=
''
struct
TextInputExample
{
@
State
text
:
string
=
''
;
controller
:
TextInputController
=
new
TextInputController
();
build
()
{
Column
()
{
TextInput
({
placeholder
:
'
input your word
'
})
.
placeholderColor
(
"
rgb(0,0,225)
"
)
.
placeholderFont
({
size
:
30
,
weight
:
100
,
family
:
'
cursive
'
,
style
:
FontStyle
.
Italic
})
TextInput
({
placeholder
:
'
input your word
...
'
,
controller
:
this
.
controller
})
.
placeholderColor
(
Color
.
Grey
)
.
placeholderFont
({
size
:
14
,
weight
:
400
})
.
caretColor
(
Color
.
Blue
)
.
height
(
50
)
.
fontSize
(
30
)
.
fontWeight
(
FontWeight
.
Bold
)
.
fontFamily
(
"
sans-serif
"
)
.
fontStyle
(
FontStyle
.
Normal
)
.
fontColor
(
Color
.
Red
)
.
width
(
400
)
.
height
(
40
)
.
margin
(
20
)
.
fontSize
(
14
)
.
fontColor
(
Color
.
Black
)
.
onChange
((
value
:
string
)
=>
{
this
.
text
=
value
this
.
text
=
value
;
})
Text
(
this
.
text
)
Button
(
'
Set caretPosition 1
'
)
.
margin
(
15
)
.
onClick
(()
=>
{
// 将光标移动至第一个字符后
this
.
controller
.
caretPosition
(
1
);
})
Text
(
this
.
text
).
width
(
'
90%
'
)
}
// 密码输入框
TextInput
({
placeholder
:
'
input your password...
'
})
.
width
(
400
)
.
height
(
40
)
.
margin
(
20
)
.
type
(
InputType
.
Password
)
.
maxLength
(
9
)
.
showPasswordIcon
(
true
)
// 内联风格输入框
TextInput
({
placeholder
:
'
inline style
'
})
.
width
(
400
)
.
height
(
50
)
.
margin
(
20
)
.
borderRadius
(
0
)
.
style
(
TextInputStyle
.
Inline
)
}.
width
(
'
100%
'
)
}
}
```
![
zh-cn_image_0000001252769643
](
figures/zh-cn_image_0000001252769643.gif
)
### 设置光标
```
ts
// xxx.ets
@
Entry
@
Component
struct
TextInputExample2
{
@
State
text
:
string
=
''
controller
:
TextInputController
=
new
TextInputController
()
build
()
{
Column
()
{
TextInput
({
placeholder
:
'
Please input your words.
'
,
controller
:
this
.
controller
})
Button
(
'
caretPosition
'
)
.
onClick
(()
=>
{
this
.
controller
.
caretPosition
(
4
)
})
}
}
}
```
![
zh-cn_image_0000001208256092
](
figures/zh-cn_image_0000001208256092.png
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录