HarmonyOS TextArea获取焦点
有一个页面由List组成,里面有很多ItemView,然后我的这个页面 还有一个评论输入组件,起名为:CommentPublishBar
代码如下:
@Preview
@Component
export default struct CommentPublishBar {
@Prop keyboardShow: boolean = false //软键盘当前是否展示
@Prop showHeight: number = getScreenWidth()
@State textAreaHeight: number = 0;
@Prop postData: PostDataBean
@Prop rid: number = 0;
@State content: string = ''
commentPublisher: CommentPublisher = new CommentPublisher()
@Link commentList: Comment[]
textInputController: TextAreaController = new TextAreaController()
aboutToAppear(): void {
}
build() {
Column() {
Column()
.backgroundColor(Color.Transparent)
.width('100%')
.height(this.keyboardShow ? px2vp(this.showHeight) - 50 - (this.textAreaHeight - 38) : 0)
.onClick(() => {
this.closePublish(false)
})
Row() {
TextArea({
placeholder: '说亿点好听的',
controller: this.textInputController,
text: this.content
})
.width(this.keyboardShow ? px2vp(getScreenWidth()) - 96 : px2vp(getScreenWidth()) - 32)
.backgroundColor($r('app.color.BG_2'))
.borderRadius(18)
.margin({ left: 16, right: 16 })
.fontColor($r('app.color.CT_2'))
.placeholderColor($r('app.color.Text_4'))
.fontSize(15)
.padding({ left: 12 })
.constraintSize({
minHeight: 38
})
.onChange((value) => {
this.content = value
})
.onAreaChange((oldValue, newValue) => {
if (typeof newValue.height === 'number') {
this.textAreaHeight = newValue.height
}
}
)
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
if (this.keyboardShow) {
Text('发布')
.width(58)
.height(32)
.borderRadius(4)
.backgroundColor($r('app.color.CM_Blue'))
.textAlign(TextAlign.Center)
.fontColor($r('app.color.CW'))
.fontSize(14)
.onClick(() => {
this.commentPublisher.localId = systemDateTime.getTime().toString()
ToastUtils.showToast('评论发送中')
this.commentPublisher.checkReviewContent(this.postData, this.content, this.postData.id, this.rid, (data: PostReviewResult) => {
let list: Comment[] = []
list.push(data.comment)
for (let item of this.commentList) {
list.push(item)
}
this.commentList = list
})
this.closePublish(true)
})
}
}.width('100%')
.alignItems(VerticalAlign.Bottom)
.padding({ top: 6, bottom: 6 })
.backgroundColor($r('app.color.CB'))
}
}
closePublish(needClearContent: boolean) {
this.rid = 0
inputMethod.getInputMethodController().stopInputSession()
this.getUIContext().getFocusController().clearFocus()
if (needClearContent) {
this.content = ''
}
}
getTextAreaHeight() {
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
希望点击itemView可以和直接点击TextArea达到同样的效果,唤起软键盘,TextArea获取焦点,应该怎么做
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS TextArea组件如何主动获取焦点
557浏览 • 1回复 待解决
HarmonyOS TextInput或TextArea如何自动获取焦点
678浏览 • 1回复 待解决
HarmonyOS TextArea如何自动获取焦点弹出键盘
871浏览 • 1回复 待解决
HarmonyOS TextArea无法自动获取焦点弹出键盘
776浏览 • 1回复 待解决
HarmonyOS 文本输入框TextArea主动获取焦点的方法
1454浏览 • 1回复 待解决
HarmonyOS 代码是弹窗中的TextArea组件,在onAppear的时候获取焦点,有概率获取到焦点但是输入法未弹出
419浏览 • 1回复 待解决
HarmonyOS Image获取焦点和失去焦点失效
603浏览 • 1回复 待解决
HarmonyOS 主动获取组件焦点
844浏览 • 1回复 待解决
HarmonyOS 主动获取焦点失败
888浏览 • 1回复 待解决
HarmonyOS Button组件无法触发获取焦点和失去焦点事件
1062浏览 • 1回复 待解决
textInput组件获取焦点和失去焦点的事件
1439浏览 • 1回复 待解决
HarmonyOS 获取焦点api提示异常
723浏览 • 1回复 待解决
HarmonyOS TextInput自动获取焦点问题
803浏览 • 1回复 待解决
HarmonyOS TextArea填充值,如何自动滚动到文本底部和如何手动失去焦点
1181浏览 • 1回复 待解决
HarmonyOS TextInput如何通过代码获取焦点
738浏览 • 1回复 待解决
HarmonyOS TextInput组件无法自动获取焦点
1022浏览 • 1回复 待解决
HarmonyOS 如何控制自定义键盘获取焦点和失去焦点
706浏览 • 1回复 待解决
HarmonyOS 获取焦点弹出键盘后,点击空白区域不能自动取消焦点
685浏览 • 1回复 待解决
HarmonyOS 用focusControl.requestFocus获取焦点失败
610浏览 • 1回复 待解决
HarmonyOS TextInput如何获取焦点但不弹出键盘
609浏览 • 1回复 待解决
TextInput组件获取焦点的几种场景
3948浏览 • 1回复 待解决
focusControl.requestFocus获取焦点的问题
865浏览 • 1回复 待解决
HarmonyOS 输入框获取焦点后无法弹出
762浏览 • 1回复 待解决
如何判断音频焦点的获取和丢失?
6776浏览 • 1回复 待解决
TextInput输入框如何失去焦点?输入框获取焦点后,点击页面上其他任意地方无法失去焦点,焦点在输入框中
3225浏览 • 1回复 待解决
可以参考一下下面的demo