From 0a90ec6cffda4e7cb9bd8095ed100309ea9e7850 Mon Sep 17 00:00:00 2001 From: lvyuanyuan Date: Thu, 26 Jun 2025 17:36:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ModifyBackgroundColorOfPressedState.ets | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ArkUI/entry/src/main/ets/pages/ModifyBackgroundColorOfPressedState.ets b/ArkUI/entry/src/main/ets/pages/ModifyBackgroundColorOfPressedState.ets index df01cf6..9dddeb5 100644 --- a/ArkUI/entry/src/main/ets/pages/ModifyBackgroundColorOfPressedState.ets +++ b/ArkUI/entry/src/main/ets/pages/ModifyBackgroundColorOfPressedState.ets @@ -21,23 +21,30 @@ @Entry @Component struct Index { - @Styles - pressedStyles() { - .backgroundColor(Color.White) - } + @State modifier: MyTextInputModifier = new MyTextInputModifier(); build() { Row() { Column() { - TextInput() - .backgroundColor(Color.White) - .stateStyles({ - pressed: this.pressedStyles, - }) + TextInput({ placeholder: 'test' }) + .width('80%') + .height(100) + .attributeModifier(this.modifier) } .width('100%') } .height('100%') } } + +class MyTextInputModifier implements AttributeModifier { + applyNormalAttribute(instance: TextInputAttribute): void { + instance.backgroundColor(Color.Grey); + } + + applyPressedAttribute(instance: TextInputAttribute): void { + instance.backgroundColor(Color.Blue); + } +} + // [End modify_background_color_of_pressed_state] \ No newline at end of file -- Gitee