1 Star 0 Fork 1

pandafactory/gopher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TabsExample.ets 3.53 KB
一键复制 编辑 原始数据 按行查看 历史
pandafactory 提交于 2024-03-10 23:47 +08:00 . 适配API 11
export class BarPositionOption {
selects: Array<SelectOption> = [];
positions: Array<BarPosition> = [];
}
const barPositionOptions: BarPositionOption = {
selects: [
{ value: 'BarPosition.Start' },
{ value: 'BarPosition.End' }],
positions: [
BarPosition.Start,
BarPosition.End]
}
@Component
export struct TabsExample {
private controller: TabsController = new TabsController()
@State private barPosition: BarPosition = BarPosition.Start;
@State private index: number = 0;
@State private vertical: boolean = false;
@State private scrollable: boolean = true;
@State private useBuilder: boolean = true;
@State private hideTabBar: boolean = false;
build() {
Column() {
Tabs({ barPosition: this.barPosition, index: this.index, controller: this.controller }) {
TabContent() {
Column().width('100%').height('100%').backgroundColor('#00CB87')
}.tabBar('green')
TabContent() {
Column().width('100%').height('100%').backgroundColor('#007DFF')
}.tabBar('blue')
}
.width(360)
.height(296)
.vertical(this.vertical)
.scrollable(this.scrollable)
.barWidth((this.hideTabBar && this.vertical) ? 0 : -1)
.barHeight((this.hideTabBar && !this.vertical) ? 0 : -1)
.barMode(BarMode.Fixed)
.animation({
duration: 500
})
// barPosition
Column() {
Row() {
Text('barPosition')
.fontSize(16)
.fontWeight(FontWeight.Bold)
Select(barPositionOptions.selects)
.value('BarPosition.Start')
.font({ size: 12 })
.optionFont({ size: 12 })
.onSelect((index: number) => {
this.barPosition = barPositionOptions.positions[index];
})
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.backgroundColor($r('sys.color.ohos_id_color_background'))
// index
Row() {
Text('index')
.fontSize(16)
.fontWeight(FontWeight.Bold)
Slider({ max: 5 })
.onChange((value: number, mode: SliderChangeMode) => {
this.index = value;
})
}
.backgroundColor($r('sys.color.ohos_id_color_background'))
// vertical
Row(){
Text('vertical')
.fontSize(16)
.fontWeight(FontWeight.Bold)
Toggle({ type:ToggleType.Switch, isOn: this.vertical})
.onChange((isOn:boolean)=> {
this.vertical = isOn;
})
}.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.backgroundColor($r('sys.color.ohos_id_color_background'))
// scrollable
Row(){
Text('scrollable')
.fontSize(16)
.fontWeight(FontWeight.Bold)
Toggle({ type:ToggleType.Switch, isOn: this.scrollable})
.onChange((isOn:boolean)=> {
this.scrollable = isOn;
})
}.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.backgroundColor($r('sys.color.ohos_id_color_background'))
// hideTabBar
Row(){
Text('hideTabBar')
.fontSize(16)
.fontWeight(FontWeight.Bold)
Toggle({ type:ToggleType.Switch, isOn: this.hideTabBar})
.onChange((isOn:boolean)=> {
this.hideTabBar = isOn;
})
}.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.backgroundColor($r('sys.color.ohos_id_color_background'))
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pandafactory/gopher.git
git@gitee.com:pandafactory/gopher.git
pandafactory
gopher
gopher
master

搜索帮助