公共样式提取到一个公共的文件中

是否能将多个样式提取到一个公共文件。提供给多个ets文件使用(例如H5中的.css文件,可提供给多个h5页面引入使用)。

HarmonyOS
2024-09-23 13:01:20
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

attributeModifier当前支持封装一个样式导出供其他组件使用,示例如下:

// CommonAttribute.ets  
export class TitleTextAttribute implements AttributeModifier<TextAttribute> {  
  applyNormalAttribute(instance: TextAttribute): void {  
    instance.backgroundColor(Color.Black)  
    instance.fontColor(Color.White)  
    instance.fontSize(40)  
  }  
}  
  
// Index.ets  
import { TitleTextAttribute } from './CommonAttribute'  
  
@Entry  
@Component  
struct Index {  
  @State modifier: TitleTextAttribute = new TitleTextAttribute()  
  build() {  
    Row() {  
      Column() {  
        Text('Hello World')  
          .attributeModifier(this.modifier)  
      }  
      .width('100%')  
    }  
    .height('100%')  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
分享
微博
QQ
微信
回复
2024-09-23 18:34:21
相关问题
需要提取到公共har包吗?
899浏览 • 1回复 待解决
java怎么读取公共目录下文件
3131浏览 • 1回复 待解决
HarmonyOS 根据后缀获取公共文件
503浏览 • 1回复 待解决
HarmonyOS 公共组件封装
1043浏览 • 1回复 待解决
HarmonyOS 如何把文件存储到公共目录
889浏览 • 1回复 待解决
HarmonyOS 如何实现公共customdialog
429浏览 • 1回复 待解决