SideBarContainer
表示侧边栏容器,它可以添加两个子组件,第一个子组件表示侧边栏,第二个子组件表示内容区,本节笔者简单介绍一下 SideBarContainer
的简单使用。
interface SideBarContainerInterface {
(type?: SideBarContainerType): SideBarContainerAttribute;
}
SideBarContainerType
定义了一下 2 中类型:简单样例如下所示:
@Entry @Component struct SideBarContainerTest {
build() {
SideBarContainer(SideBarContainerType.Overlay) {
Column() {
Text("侧边栏区域")
.width("100%")
.height("100%")
.fontSize(30)
.textAlign(TextAlign.Center)
}
.width(10)
.height("100%")
.backgroundColor("#aabbcc")
Column() {
Text("侧边栏区域")
.width("100%")
.height("100%")
.fontSize(30)
.textAlign(TextAlign.Center)
}
.width("100%")
.height("100%")
.backgroundColor("#bbccaa")
}
.width('100%')
.height('100%')
}
}
样例运行结果如下图所示:
declare class SideBarContainerAttribute extends CommonMethod<SideBarContainerAttribute> {
showSideBar(value: boolean): SideBarContainerAttribute;
controlButton(value: ButtonStyle): SideBarContainerAttribute;
showControlButton(value: boolean): SideBarContainerAttribute;
sideBarWidth(value: number): SideBarContainerAttribute;
minSideBarWidth(value: number): SideBarContainerAttribute;
maxSideBarWidth(value: number): SideBarContainerAttribute;
}
declare interface ButtonStyle {
left?: number;
top?: number;
width?: number;
height?: number;
icons?: {
shown: string | PixelMap | Resource;
hidden: string | PixelMap | Resource;
switching?: string | PixelMap | Resource;
};
}
ButtonStyle
参数说明如下:简单样例如下所示:
@Entry @Component struct SideBarContainerTest {
build() {
SideBarContainer(SideBarContainerType.Overlay) { // 设置侧边栏样式为悬浮态
Column() { // 第一个子组件为侧边栏视图
Text("侧边栏区域")
.width("100%")
.height("100%")
.fontSize(30)
.textAlign(TextAlign.Center)
}
.width(10)
.height("100%")
.backgroundColor("#aabbcc")
Column() { // 第二个子组件为内容区视图
Text("内容区域")
.width("100%")
.height("100%")
.fontSize(30)
.textAlign(TextAlign.Center)
}
.width("100%")
.height("100%")
.backgroundColor("#bbccaa")
}
.width('100%')
.height('100%')
.sideBarWidth(150) // 设置侧边栏宽度为150
.minSideBarWidth(100) // 设置侧边栏最小宽度为100
.maxSideBarWidth(200) // 设置侧边栏最大宽度为200
.controlButton({ // 设置侧边栏控制按钮的样式
width: 30, // 设置侧边栏控制按钮宽度为30
height: 30, // 设置侧边栏控制按钮高度为30
top: 15, // 设置侧边栏控制按钮距离容器顶部为15
icons: { // 设置侧边栏控制按钮图片
shown: $r("app.media.icon_back"), // 设置侧边栏显示时控制按钮的图标。
hidden: $r("app.media.icon_menu"), // 设置侧边栏隐藏时控制按钮的图标。
switching: $r("app.media.icon_back") // 设置侧边栏显示和隐藏状态切换时控制按钮的图标。
}
})
}
}
样例运行结果如下图所示:
declare class SideBarContainerAttribute extends CommonMethod<SideBarContainerAttribute> {
onChange(callback: (value: boolean) => void): SideBarContainerAttribute;
}
value
为 true 表示菜单栏显示显示,false表示菜单栏隐藏。如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。