鸿蒙使用总结 持续更新...
1. Text
Text(`sharedName: ${this.sharedName}`)
2. 布局约束
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
3.父子界面跳转
// 父
import { ChildPage } from './ChildPage'
private pathStack: NavPathStack = new NavPathStack()
build() {
Navigation(this.pathStack) {
//这里实现了跳转
Button('push 到子页面')
.onClick(() => {
this.pathStack.pushPath({
name: 'ChildPage'
})
})
}
.title('ParentPage')
.navDestination(this.pageMap)
}
@Builder
pageMap(name: string) {
if (name === 'ChildPage') {
ChildPage()
}
}
// 子
@Component
export struct ChildPage { //export 要有
build() {
NavDestination() {
}
.title('ChildPage')
}
}
4. 如何更换应用图标
Step1: 打开 AppScope/app.json5
{
"app": {
"icon": "$media:layered_image", // 引用分层图标
"label": "$string:app_name"
}
}
Step 2:
- 2.1尺寸:1024×1024px 正方形 PNG,不用自己加圆角,系统自动裁切
- 2.2 分层要求:
background.png:背景底色,不能透明(纯色 / 渐变底板)
foreground.png:Logo 前景,必须透明通道,图形不要贴边(防止圆角裁掉) - 2.3 格式:仅 PNG,禁止 jpg、svg 做桌面分层图标
Step 3:替换图片
项目根目录 → AppScope/resources/base/media/