OpenHarmony开发者论坛
标题:
SideBarContainer如何设置controlButton属性?
[打印本页]
作者:
zhanglin
时间:
2023-8-31 10:24
标题:
SideBarContainer如何设置controlButton属性?
[md]【问题描述】
SideBarContainer,想设置按钮的位置,controlButton属性不会设置,官网也没有使用示例,能给个例子吗?
![image.png](data/attachment/forum/202308/31/102406yn2cwknizl5z8uwi.png "image.png")
【运行环境】
硬件:rk3568; ROM: 3.2 Beta5 ; API 9;
[/md]
作者:
gelsang
时间:
2023-9-1 09:11
参考以下示例
@Entry
@Component
struct SideBarContainerExample {
normalIcon : Resource = $r("app.media.icon")
selectedIcon: Resource = $r("app.media.icon")
@State arr: number[] = [1, 2, 3]
@State current: number = 1
build() {
SideBarContainer(SideBarContainerType.Embed)
{
Column() {
ForEach(this.arr, (item, index) => {
Column({ space: 5 }) {
Image(this.current === item ? this.selectedIcon : this.normalIcon).width(64).height(64)
Text("Index0" + item)
.fontSize(25)
.fontColor(this.current === item ? '#0A59F7' : '#999')
.fontFamily('source-sans-pro,cursive,sans-serif')
}
.onClick(() => {
this.current = item
})
}, item => item)
}.width('100%')
.justifyContent(FlexAlign.SpaceEvenly)
.backgroundColor('#19000000')
Column() {
Text('SideBarContainer content text1').fontSize(25)
Text('SideBarContainer content text2').fontSize(25)
}
.margin({ top: 50, left: 20, right: 30 })
}
.sideBarWidth(150)
.minSideBarWidth(50)
.controlButton({left:32,
top:32,
width:32,
height:32,
icons:{shown: $r("app.media.icon"),
hidden: $r("app.media.icon"),
switching: $r("app.media.icon")}})
.maxSideBarWidth(300)
.onChange((value: boolean) => {
console.info('status:' + value)
})
}
}
复制代码
欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/)
Powered by Discuz! X3.5