HarmonyOS 鸿蒙Next 如何去掉键盘与Dialog空隙
HarmonyOS 鸿蒙Next 如何去掉键盘与Dialog空隙
@CustomDialog 弹出键盘 与 Dialog有个空隙 如何去掉呢?
设置
expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM])
this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE)
this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.OFFSET)
这些都不管用
设置
expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM])
this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE)
this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.OFFSET)
这些都不管用
更多关于HarmonyOS 鸿蒙Next 如何去掉键盘与Dialog空隙的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3 回复
键盘抬起会避让一个ux设置的paddingBottom,弹框和软键盘距离16vp,这个是dialog的规格。
entry里height的100%并不是真的全频,不包含状态栏和底部,弹起来的有缝隙,dy向下偏移个底部的高度就能遮挡住缝隙
@Entry
@Component
struct CustomDialogUser {
dialogController: CustomDialogController = new CustomDialogController({
builder: CommentInputDialog({}),
alignment: DialogAlignment.Bottom,
customStyle: true,
offset: { dx: 0, dy: 100 }
})
build() {
Column() {
Button('click me')
.onClick(() => {
this.dialogController.open()
})
}.width('100%').height('100%').backgroundColor(Color.Red)
}
}
可以将customStyle设置为true,并且给弹框内部的Column设置偏移.offset({ x: 0, y: 20})
@CustomDialog
export struct CommentInputDialog{
private statusBarHeight: number = (AppStorage.get('statusBarHeight') as number);
controller?: CustomDialogController
private commentContent: string = ''
onTap: (content: string) => void = () => {
};
build() {
Column(){
Image($r('app.media.black_close_icon'))
.width(26)
.height(26)
.onClick(() =>{
this.controller?.close();
})
TextArea({ placeholder: '我来说两句...', text: this.commentContent})
.placeholderColor($r('app.color.color909099'))
.backgroundColor($r('app.color.colorF7F8F9'))
.borderRadius(4)
.placeholderFont({
size: '17fp',
family: CommonConstants.SI_YUAN
})
.backgroundColor(Color.White)
.enterKeyType(EnterKeyType.Done)
.defaultFocus(true)
.onChange((value) => {
this.commentContent = value;
}).margin({top: 10, bottom: 10})
.layoutWeight(1)
Text('确认')
.width(60)
.height(30)
.fontColor(Color.White)
.fontSize('14fp')
.fontFamily(CommonConstants.SI_YUAN)
.textAlign(TextAlign.Center)
.backgroundColor($r('app.color.colorF21333'))
.borderRadius(15)
.onClick(() =>{
this.onTap(this.commentContent)
})
}
.width(CommonConstants.FULL_PERCENT)
.height(210 + this.statusBarHeight)
.padding({left: 15, top: 15, right: 15, bottom: 10 + this.statusBarHeight })
.alignItems(HorizontalAlign.End)
.backgroundColor($r('app.color.colorF1F2F3'))
.borderRadius({topLeft: 15, topRight: 15})
.offset({ x: 0, y: 20}) // 设置偏移
}
}
更多关于HarmonyOS 鸿蒙Next 如何去掉键盘与Dialog空隙的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
能提供下demo代码和具体的样式截图吗,不太理解你说的空隙到底指的是啥
在HarmonyOS 鸿蒙Next中,若想要去掉键盘与Dialog之间的空隙,可以尝试以下方法:
- 调整Dialog布局:确保Dialog的布局参数正确设置,特别是高度和宽度。有时,空隙可能是由于Dialog布局超出了其应有的范围或未正确适应键盘弹出后的屏幕布局。
- 监听键盘高度变化:通过监听键盘高度变化事件,动态调整Dialog的位置或高度,以确保其与键盘紧密贴合。可以使用
window.on('keyboardHeightChange', callback)
来监听键盘高度变化。 - 设置弹窗样式:在创建Dialog时,检查并设置合适的弹窗样式,包括对齐方式、边距等,以确保弹窗与键盘之间没有不必要的空隙。
- 覆盖底部导航栏:如果Dialog需要在全屏模式下显示,确保在显示Dialog之前将当前页面设置为全屏模式,并调整Dialog的高度以覆盖底部导航栏(如有)。
如果以上方法仍然无法解决问题,可能是由于特定的系统行为或布局限制导致的。此时,建议深入检查Dialog的布局代码和样式设置,或参考HarmonyOS的官方文档和开发者社区以获取更多帮助。如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html。