鸿蒙OS这个自定义键盘能动态切换是自定义还是系统键盘吗?

鸿蒙OS这个自定义键盘能动态切换是自定义还是系统键盘吗?
image.png

阅读 396
avatarAI BotBETA

鸿蒙OS的自定义键盘可以动态切换为自定义键盘或系统键盘。这通常取决于用户的设置和偏好。用户可以在系统设置中选择使用自定义键盘还是系统默认键盘。

然而,从您提供的图片来看,似乎是在某个应用内部进行的键盘切换。如果是这样的话,这取决于该应用是否支持在运行时动态切换键盘。有些应用可能允许用户在应用内部选择使用自定义键盘或系统键盘,而有些应用可能只支持系统默认键盘。

为了更准确地回答您的问题,我需要更多的上下文信息,例如您正在使用的具体应用、鸿蒙OS的版本以及您尝试实现的具体功能。

请注意,我的回答是基于一般的编程和操作系统知识,并且假设鸿蒙OS遵循常见的编程和操作系统实践。然而,由于鸿蒙OS是由华为开发的专有操作系统,它可能具有一些独特的特性和行为,这些特性和行为可能与我提供的答案不完全一致。因此,建议您查阅鸿蒙OS的官方文档或联系华为的技术支持以获取更准确的答案。

2 个回答

鸿蒙 OS 中可以实现自定义键盘和系统键盘的切换,你可尝试使用关闭键盘->转移焦点->然后再转回来从而实现从自定义键盘到系统默认键盘的转换,示例如下:

// xxx.ets
@Entry
@Component
struct TextInputExample {
  controller: TextInputController = new TextInputController()
  @State inputValue: string = ""
  @State isShowSystemKeyboard: boolean = false
  @State threeButtonColor: string = '#90EE90'

  // 自定义键盘组件
  @Builder CustomKeyboardBuilder() {
    Column() {
      Button('x')
       .onClick(() => {
          // 关闭自定义键盘
          this.controller.stopEditing()
          // this.isShowSystemKeyboard = true
        })
      Grid() {
        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item:number|string) => {
          GridItem() {
            Button(item + "")
             .width(110).onClick(() => {
                this.inputValue += item
              })
          }
        })
      }.maxCount(3).columnsGap(10).ro
    }
  }
}

也可以参考以下示例:

// xxx.ets
@Entry
@Component
struct TextInputExample {
  controller: TextInputController = new TextInputController()
  @State inputValue: string = ""

  // 自定义键盘组件
  @Builder
  CustomKeyboardBuilder() {
    Column() {
      Button('close keyboard').onClick(() => {
        // 关闭自定义键盘
        this.controller.stopEditing()
      })
      Grid() {
        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => {
          GridItem() {
            Button(item + "")
             .width(110).onClick(() => {
                this.inputValue += item
              })
          }
        })
      }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)
    }.backgroundColor(Color.Gray)
  }

  build() {
    Column() {
      TextInput({ controller: this.controller, text: this.inputValue })// 绑定自定义键盘
       .customKeyboard(this.CustomKeyboardBuilder()).margin(10).border({ width: 1 })
    }
  }
}

还有以下示例:

@Entry
@Component
struct CustomDialogUser {
  @State showFlag: Visibility = Visibility.Visible;
  keyboardBuilder: CustomBuilder = () => {
    this.CustomKeyboardBuilder()
  }
  @State inputValue: string = ""
  @Styles
  clickStyle() {
   .backgroundColor(Color.Grey)
  }
  @Styles
  normalStyle() {
   .backgroundColor(Color.White)
  }
  // 自定义键盘组件
  @Builder
  CustomKeyboardBuilder() {
    Column() {
      Grid() {
        ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'], (item: number | string) => {
          GridItem() {
            Button(item + "")
             .width("100%")
             .onClick(() => {
                this.inputValue += item
              })
             .backgroundColor(Color.Gray)
          }
         .width("30%")
        }
      }
     .width("100%")
     .maxCount(3)
     .columnsGap(10)
     .rowsGap(10)
     .padding(5)
    }
   .width("100%")
   .backgroundColor(Color.White)
  }
  dialogC
}

主要取决于用户的个人设置以及应用是否支持在运行时更改键盘类型。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进