完整示例参考如下:
@Entry @Component struct TextAreaExample { controller: TextAreaController = new TextAreaController(); @State inputValue: string = ''; // 自定义键盘组件 @Builder CustomKeyboardBuilder() { Column() { Grid() { ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => { GridItem() { Button(item + '').width(110).onClick(() => { this.inputValue += item; }); }; }); } .height(0) .width(0); }.backgroundColor(Color.Gray); } build() { Column() { TextArea({ controller: this.controller, text: this.inputValue }) .customKeyboard(this.CustomKeyboardBuilder()) .margin(10) .border({ width: 1 }) .height(200); }; } }