HarmonyOS TextInput组件的使用问题?

TextInput组件,为了不响应点击事件,设置了enabled(false)属性,但同时给值了之后,颜色还是placeholder的颜色,不是font的颜色,如何处理

代码如下:

TextInput({ placeholder: "您的出发地", text: this.baseAddress })
    .commonTextInputStyle(14, $r("app.color.color33"), 14, $r("app.color.colorC6"))
    .padding({ left: 10, right: 0 })
    .enabled(false)

@Extend(TextInput)
function commonTextInputStyle(fontSize: Length, fontColor: ResourceColor, placeholderFontSize: Length,
  placeholderFontColor: ResourceColor) {
  .layoutWeight(1)
  .fontSize(fontSize)
  .borderRadius(0)
  .fontColor(fontColor)
  .maxLines(1)
  .caretColor($r("app.color.themeColor"))
  .caretStyle({ width: 2 })
  .placeholderFont({ size: placeholderFontSize })
  .placeholderColor(placeholderFontColor)
  .padding({ left: 0, right: 0 })
  .backgroundColor(Color.Transparent)
}
阅读 488
1 个回答

可以通过设置hitTestBehavior(HitTestMode.None)让TextInput不生效点击事件

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