diff --git a/ArkUI/entry/src/main/ets/pages/ModifyBackgroundColorOfPressedState.ets b/ArkUI/entry/src/main/ets/pages/ModifyBackgroundColorOfPressedState.ets index df01cf613eeddffc34cddc5c5e3dd2466b766078..9dddeb56b29349a5261780d4dbe0e88b7595ccf3 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