今天用鸿蒙代码封装一个设置页的通用代码
·
@Builder
toolsBuilder(tool: Tool) {
Row() {
if (tool.icon) {
Image(tool.icon)
.width(16)
.aspectRatio(1)
.margin({ right: 12 })
}
Text(tool.name)
.fontSize(16)
Blank()
if (tool.value) {
Text(tool.value)
.fontSize(14)
.fontColor($r('app.color.common_gray_01'))
.margin({ right: 10 })
}
Image($r('sys.media.ohos_ic_public_arrow_right'))
.width(18)
.aspectRatio(1)
.fillColor($r('app.color.common_gray_01'))
}
.height(50)
.width('100%')
.backgroundColor($r('app.color.white'))
.padding({ left: 16, right: 10 })
.borderRadius({
topLeft: tool.radius === 1 ? 8 : 0,
topRight: tool.radius === 1 ? 8 : 0,
bottomLeft: tool.radius === 2 ? 8 : 0,
bottomRight: tool.radius === 2 ? 8 : 0
})
.onClick(() => {
tool.onClick && tool.onClick()
})
}
先用@Builder进行代码封装好,那么我们使用的时候就可以直接去使用了
Row(){
this.toolsBuilder({name: '昵称'})
}
那么我们这个时候就生成了一个封装好的设置页
更多推荐


所有评论(0)