arkts_arkUI组件按钮点击改变颜色

复制代码
import ark from '@system.ark';
import { View, Text, Button } from '@ui';
 
@Entry
@Component
struct MyComponent {
  @State color: string = '#ff0000'; // 初始颜色为红色
 
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Button('点击我')
        .onClick(() => {
          this.color = '#00ff00'; // 点击后改变颜色为绿色
        })
        .style({
          backgroundColor: this.color, // 使用状态变量动态设置背景色
          width: 200,
          height: 50,
        });
    }
    .width('100%')
    .height(300)
  }
}
复制代码

arkts_arkUI组件按钮点击改变颜色

posted @   txwtech  阅读(1039)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2021-05-04 软件工程领域工程硕士培养方案
2020-05-04 东方步进电机马达驱动板CVK系列说明书
点击右上角即可分享
微信分享提示