玫德集团|
UI
HarmonyOS 5
TextArea获取到焦点时,软键盘未能将输入框顶起来
聊天页面中有个emoji表情面板,当表情面板显示的时候点击输入框,通过对监听
收起
自动换行
深色代码主题
复制
.onBlur和收起
自动换行
深色代码主题
复制
.onEditChange方法,发现TextArea已经获取到了焦点,但是软键盘未能将输入框顶起来,代码如下:收起
自动换行
深色代码主题
复制
TextArea({ controller: this.controller, text: this.content })
.borderRadius(6)
.layoutWeight(1)
.backgroundColor('#F7F7F7')
.onBlur(()=>{
LogUtil.info('---onBlur---')
})
.onEditChange((isEdit: boolean) => {
if(isEdit){
this.showAddPanel = false
this.showEmoji = false
this.showRecordVoice = false
}
})
.maxLines(0)
.onChange((value) => {
this.content = value
this.showSendBtn = value.trim().length > 0
}) 2
浏览113 发布于2026-01-14 02:37山东
全部评论
最多点赞
最新发布
最早发布
仙银
自行处理键盘避让问题,将页面设置为不避让键盘,然后监听键盘高度,给输入框部分增加padding/margin为键盘高度。
收起
自动换行
深色代码主题
复制
/**
* @fileName : EmotionView.ets
* @author : @cxy
* @date : 2025/12/19
* @description : 表情面板示例
*/
import { EmotionComponent } from "./EmotionComponent"
import { Emotion } from "./EmotionImage"
import { window } from "@kit.ArkUI"
import { KeyboardAvoidMode } from '@kit.ArkUI';
enum ShowType {
None = 0,
Text = 1,
Emotion = 2
}
@Component
export struct EmotionView {
@State enableSend: boolean = false
@State showType: ShowType = ShowType.None
@State keybordHeight: number = 314
@State bottomSafeHeight: number = 34 //TODO:监听avoidAreaChange获取
private controller: RichEditorController = new RichEditorController()
aboutToAppear(): void {
const context = this.getUIContext().getHostContext()
if (context) {
this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.NONE)
window.getLastWindow(context).then((win) => {
win.setWindowLayoutFullScreen(true)
win.on('keyboardHeightChange', this.keyboardHeightChange)
})
}
}
aboutToDisappear(): void {
const context = this.getUIContext().getHostContext()
if (context) {
window.getLastWindow(context).then((win) => {
win.off('keyboardHeightChange', this.keyboardHeightChange)
})
}
}
build() {
Column() {
Row({ space: 10 }) {
RichEditor({
controller: this.controller
})
.id('richEditorId')
.backgroundColor('#f0f0f0')
.borderRadius(6)
.onEditingChange((isEditing) => {
if (isEditing) {
this.showType = ShowType.Text
} else {
if (this.showType === ShowType.Text) {
this.showType = ShowType.None
}
}
})
.onDidChange((rangeBefore: TextRange, rangeAfter: TextRange) => {
this.enableSend = this.controller.getSpans().length > 0
})
.layoutWeight(1)
Text(this.showType === ShowType.Emotion ? '文本' : '表情')
.fontSize(20)
.onClick(() => {
if (this.showType === ShowType.Emotion) {
this.showType = ShowType.Text
focusControl.requestFocus('richEditorId');
} else {
this.controller.stopEditing()
this.showType = ShowType.Emotion
}
})
}
.alignItems(VerticalAlign.Center)
.padding(10)
EmotionComponent({
emotionHeight: this.keybordHeight,
enableSend: this.enableSend,
onSelectEmoji: (e: string) => {
this.controller.addTextSpan(e)
},
onDeleteEmoji: () => {
// TODO: 删除
// this.controller.deleteSpans()
},
onSendEmotion: (e?: Emotion) => {
console.dir(e)
}
})
.visibility(this.showType === ShowType.Emotion ? Visibility.Visible : Visibility.None)
}
.width('100%')
.height('100%')
.alignItems(HorizontalAlign.Center)
.justifyContent(FlexAlign.End)
.padding({
bottom: this.getBottomHeight()
})
}
getBottomHeight(): number {
if (this.showType === ShowType.Text) {
return this.keybordHeight
}
if (this.showType === ShowType.Emotion) {
return 0
}
return this.bottomSafeHeight //底部安全区域高度,
}
private keyboardHeightChange = (data: number) => {
if (data > 0) {
this.keybordHeight = this.getUIContext().px2vp(data)
}
}
}可以参考这篇自定义表情包键盘
展开全部 
2楼回复于2026-01-15 08:37 来自四川
华夏
1楼回复于2026-01-14 06:09 来自北京
写回答
所见即所得编辑器, editor1
工具栏 撤消 快捷键 Ctrl+Z 重做 快捷键 Ctrl+Y 格式刷 快捷键 Ctrl+Shift+C 清除格式 加粗 快捷键 Ctrl+B 倾斜 快捷键 Ctrl+I 下划线 快捷键 Ctrl+U 删除线格式调整字号 文本颜色 背景颜色 增加缩进量 减少缩进量 左对齐 居中 右对齐 两端对齐段落间距行间距 项目列表 编号列表 插入水平线 块引用 插入/编辑超链接 快捷键 Ctrl+K 取消超链接 图片 表格 上传附件 导入Word 插入代码 MD编辑器 全屏模式
0/50000
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
- 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
- 如您发布的内容为转载内容,请注明内容来源。
我要提问题
相关推荐
换一批
1
HarmonyOS 浏览器在第一次请求剪切板权限的时候会抢已次输入框的焦点,软键盘会闪一下(API12+)
2
HarmonyOS 如何取消页面输入框避让系统软键盘?(API12+)
3
HarmonyOS 如何让输入框规避软键盘,同时输入框下面的元素也不被软键盘遮挡(API12+)
4
HarmonyOS emoji表情使用 (API12+)
5
HarmonyOS 软键盘的send操作会导致TextArea失去焦点(API14+)
6
HarmonyOS 设置默认获取焦点键盘无法弹起(API12+)
7
HarmonyOS TextArea会自动获取焦点(API12+)
8
HarmonyOS 输入法应用在键盘的输入框内调requestFocus不生效(API12+)
了解社区公约,与您携手共创和谐专业的开发者社区。





































苏公安网备 32011402010933号