API20后推荐使用splitPlaceholder接口,可以使用splitPlaceholder设置右侧页面显示默认占位页。
import { ComponentContent } from '@kit.ArkUI';
@Builder
function PlaceholderPage() {
Column() {
Text("分栏模式占位页")
.fontSize(22)
.fontWeight(500)
.margin({ top: 200 });
}.width("100%")
.height("100%");
}
@Entry
@Component
struct NavigationExampleDemo {
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
placeholder = new ComponentContent(this.getUIContext(), wrapBuilder(PlaceholderPage));
@Builder
NavigationTitle() {
Column() {
Text('Title')
.fontColor('#182431')
.fontSize(20)
.lineHeight(30)
.fontWeight(500);
Text('subtitle')
.fontColor('#182431')
.fontSize(14)
.lineHeight(19)
.opacity(0.4)
.margin({ top: 2, bottom: 20 });
}.alignItems(HorizontalAlign.Start);
}
build() {
Column() {
Navigation() {
TextInput({ placeholder: 'search...' })
.width('90%')
.height(40)
.backgroundColor('#F1F3F5')
.margin({ top: 8 });
List({ space: 12, initialIndex: 0 }) {
ForEach(this.arr, (item: number) => {
ListItem() {
Text('' + item)
.width('90%')
.height(72)
.backgroundColor('#F1F3F5')
.borderRadius(24)
.fontSize(16)
.fontWeight(500)
.textAlign(TextAlign.Center);
};
}, (item: number) => item.toString());
}
.height(324)
.width('100%')
.margin({ top: 12, left: '10%' });
}
.title(this.NavigationTitle)
.titleMode(NavigationTitleMode.Full)
.toolbarConfiguration([
{
// $r("app.media.startIcon")需要替换为开发者所需的图像资源文件
value: '首页',
icon: $r("app.media.startIcon")
},
{
value: '菜单',
icon: $r("app.media.startIcon")
},
{
value: '我的',
icon: $r("app.media.startIcon")
}
], { backgroundColor: '#FFFFFF' })
.mode(NavigationMode.Split)
.hideTitleBar(false)
.hideToolBar(false)
.splitPlaceholder(this.placeholder);
}.width('100%').height('100%');
}
}