harmonyOS ArkTS最新跳转Navigation

devtools/2024/9/29 12:15:38/

文章目录

      • 取消标题栏
      • 初始页面(load)
        • 设置为竖屏
      • 自定义标题
      • Tabs&TabContent
        • Tabs
        • 通过divider实现了分割线各种属性
      • 图片下载

官方文档

@Entry
@Component
struct Index {@State message: string = 'Hello World'@State djs:number = 5build() {Column(){Navigation(){}.title("go to")Row(){Text(this.message).fontSize(20)}.width('100%').height('5%').backgroundColor(Color.Red)Row(){Text(this.message).fontSize(20)}.width('100%').backgroundColor(Color.Blue)Row(){Text(this.message).fontSize(20)}.width('100%').backgroundColor(Color.Blue)Stack({alignContent:Alignment.Bottom}){Text(this.message).fontSize(20)}}.height("100%").width('100%')}
}

注意:这样写其中Row的一些内容是不会呈现的,可以不用。要写也是写在NavigationNavigation里面

@Entry
@Component
struct Index {@State message: string = 'Hello World'@State djs:number = 5build() {Column(){Navigation(){}.title("go to")}.height("100%").width('100%')}
}

但是你会发现还是有标题栏
在这里插入图片描述

取消标题栏

  1. 打开你的HarmonyOS项目的配置文件config.json
  2. 定位到你想要修改的页面配置部分。
  3. metaData对象中添加customizeData数组,其中包含一个对象,该对象的name属性设置为hwc-themevalue属性设置为androidhwext:style/Theme.Emui.Light.NoTitleBar
    示例配置如下:
{"abilities": [{"orientation": "unspecified","visible": true,"name": "com.example.test.MainAbility","icon": "$media:icon","description": "$string:mainability_description","label": "$string:entry_MainAbility","type": "page","launchType": "standard","metaData": {"customizeData": [{"name": "hwc-theme","value": "androidhwext:style/Theme.Emui.Light.NoTitleBar","extra": ""}]}}]
}

通过上述设置,你可以隐藏默认的标题栏。如果你需要全屏显示,还可以添加其他属性来实现。
在这里插入图片描述

初始页面(load)

也就是这个页面不会停留很久

import router from '@ohos.router';
@Entry
@Component
struct Index {@State message: string = 'Hello World'@State countdown: number = 5; // 倒计时时间,单位秒@State isCounting: boolean = false; // 倒计时是否正在进行startCountDown(){this.isCounting = true;let seconds = this.countdownconst  inter = setInterval(()=>{seconds--this.countdown = secondsif(this.countdown <= 0){clearInterval(inter);this.isCounting = false;router.replace({url:'pages/master'})}},1000)}onPageShow(){ //页面显示加载执行this.startCountDown()}build() {Column(){Button(`跳转|${this.countdown}`).onClick(()=>{router.replace({url:'pages/master'})})}}
}

可以一横屏一竖屏就会重新加载。。。

设置为竖屏

打开config.json添加

"orientation": "portrait"

在这里插入图片描述

  • unspecified:未指定方向,由系统自动判断显示方向。
  • landscape:横屏。
  • portrait:竖屏。
  • landscape_inverted:反向横屏。
  • portrait_inverted:反向竖屏。
  • auto_rotation:随传感器旋转。
  • auto_rotation_landscape:传感器横屏旋转,包括横屏和反向横屏。
  • auto_rotation_portrait:传感器竖屏旋转,包括竖屏和反向竖屏。
  • auto_rotation_restricted:传感器开关打开,方向可随传感器旋转。
  • auto_rotation_landscape_restricted:传感器开关打开,方向可随传感器旋转为横屏,包括横屏和反向横屏。
  • auto_rotation_portrait_restricted:传感器开关打开,方向随可传感器旋转为竖屏,包括竖屏和反向竖屏。
  • locked:传感器开关关闭,方向锁定。

自定义标题

//pages.main.ets
import router from '@ohos.router'
@Entry
@Component
struct Master{@State hello:string = "hello this is master page"@State inputButton:string = "测试"build(){Column(){Button(this.inputButton,{ stateEffect: false }).backgroundColor("#F5F5F5").fontColor("#DCDCDC").width(200).height(35).onClick(()=>{router.push({url: 'pages/main_search'})})}.height('100%').width('100%')}
}

点击后跳转pages/main_search页面

@Entry
@Component
struct main_search{controller:TextInputController = new TextInputController();build(){Navigation(){TextInput({text:"",placeholder:"测试",controller:this.controller}).placeholderColor(Color.Gray)}}
}

但出现
在这里插入图片描述
为了平齐我们需要自定义标题栏

@Entry
@Component
struct main_search{controller:TextInputController = new TextInputController();@Builder title(){ // 自定义标题栏Row(){TextInput({text:"",placeholder:"测试",controller:this.controller}).placeholderColor(Color.Gray)}}build(){Navigation(){}.title(this.title())}
}

Tabs&TabContent

Tabs官方文档
TabContent官方文档

Tabs

不支持自定义组件作为子组件, 仅可包含子组件TabContent

格式为

//需要添加@State currentIndex:number = 0
Tabs({{barPosition: BarPosition.Start, index: this.currentIndex,controller:this.tabs_controller}}){TabContent(){}.tabBar({icon:<string>,text:<string>})
}

其中icon就是索引,text是名称

  • barPosition: 设置Tabs的页签位置。默认值:BarPosition.Start(左侧)还可以设置为BarPosition.End(右侧)
  • index: 显示当前索引值
  • controller:Tabs的控制器必须要有,写法@State currentIndex:number = 0
    可以自定义
//需要添加
//@State currentIndex:number = 0
//@State fontColor: string = '#182431'
//@State selectedFontColor: string = '#007DFF'@Builder tabBuilder(index:number,name:string){Column() {Text(name).fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) //当前那个索引被选中更改颜色.fontSize(16) .fontWeight(this.currentIndex === index ? 500 : 400) //选中和没选中更改字体粗细.lineHeight(22).margin({ top: 17, bottom: 7 })Divider().strokeWidth(2).color('#007DFF').opacity(this.currentIndex === index ? 1 : 0)}.width('100%')
}

你可以这么写

Tabs({{barPosition: BarPosition.Start, index: this.currentIndex,controller:this.tabs_controller}}){//绿色整体TabContent(){Column(){}.width('100%').height('100%').backgroundColor(Color.Green)}.tabBar(this.tabBuilder(0,"green"))//蓝色整体TabContent(){Column(){}.width('100%').height('100%').backgroundColor(Color.Blue)}.tabBar(this.tabBuilder(0,"blue"))
}

在这里插入图片描述

通过divider实现了分割线各种属性
Divider().strokeWidth(2).color('#007DFF').opacity(this.currentIndex === index ? 1 : 0)//.margin({ top: 7, bottom: 0 }) //可以对分割线位置进行修改

图片下载

我的图像SVG

<svg t="1727174544161" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1537" width="200" height="200"><path d="M1024 512c0-281.6-230.4-512-512-512S0 230.4 0 512s230.4 512 512 512 512-230.4 512-512z m-512 448c-249.6 0-448-198.4-448-448s198.4-448 448-448 448 198.4 448 448-198.4 448-448 448z" fill="#777777" p-id="1538"></path><path d="M627.2 505.6c44.8-38.4 76.8-89.6 76.8-153.6 0-108.8-83.2-192-192-192s-192 83.2-192 192c0 64 32 115.2 76.8 153.6-102.4 44.8-172.8 147.2-172.8 262.4 0 19.2 12.8 32 32 32s32-12.8 32-32c0-121.6 102.4-224 224-224s224 102.4 224 224c0 19.2 12.8 32 32 32s32-12.8 32-32c0-115.2-70.4-217.6-172.8-262.4zM512 480c-70.4 0-128-57.6-128-128s57.6-128 128-128 128 57.6 128 128-57.6 128-128 128z" fill="#777777" p-id="1539"></path></svg><svg t="1727174544161" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1537" width="200" height="200"><path d="M1024 512c0-281.6-230.4-512-512-512S0 230.4 0 512s230.4 512 512 512 512-230.4 512-512z m-512 448c-249.6 0-448-198.4-448-448s198.4-448 448-448 448 198.4 448 448-198.4 448-448 448z" fill="#777777" p-id="1538"></path><path d="M627.2 505.6c44.8-38.4 76.8-89.6 76.8-153.6 0-108.8-83.2-192-192-192s-192 83.2-192 192c0 64 32 115.2 76.8 153.6-102.4 44.8-172.8 147.2-172.8 262.4 0 19.2 12.8 32 32 32s32-12.8 32-32c0-121.6 102.4-224 224-224s224 102.4 224 224c0 19.2 12.8 32 32 32s32-12.8 32-32c0-115.2-70.4-217.6-172.8-262.4zM512 480c-70.4 0-128-57.6-128-128s57.6-128 128-128 128 57.6 128 128-57.6 128-128 128z" fill="#777777" p-id="1539"></path></svg>

信封SVG

<svg t="1727174609255" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2645" width="200" height="200"><path d="M914.285714 73.142857h-804.571428C51.2 73.142857 0 124.342857 0 182.857143v585.142857c0 58.514286 51.2 109.714286 109.714286 109.714286h804.571428c58.514286 0 109.714286-51.2 109.714286-109.714286v-585.142857c0-58.514286-51.2-109.714286-109.714286-109.714286z m-804.571428 73.142857h804.571428L563.2 497.371429c-14.628571 14.628571-29.257143 21.942857-51.2 21.942857s-36.571429-7.314286-51.2-21.942857L109.714286 146.285714zM73.142857 782.628571V212.114286l285.257143 285.257143L73.142857 782.628571z m80.457143 21.942858l256-256c29.257143 29.257143 65.828571 43.885714 102.4 43.885714s73.142857-14.628571 102.4-43.885714l43.885714-43.885715-43.885714 43.885715 256 256H153.6z m797.257143-36.571429v14.628571L665.6 497.371429 950.857143 212.114286v555.885714z" p-id="2646"></path></svg>

http://www.ppmy.cn/devtools/118681.html

相关文章

【HarmonyOS】应用权限原理和封装

背景 在项目中&#xff0c;避免不了需要调用系统资源和系统能力&#xff0c;比如&#xff1a;日历读写、摄像头等。因此&#xff0c;需要了解对系统资源访问权限的申请方式方法。 授权方式 包括两种授权方式&#xff0c;分别是system_grant(系统授权) 和 user_grant(用户授权)…

数字化转型:开启未来发展新引擎

在当今飞速发展的时代&#xff0c;数字化转型已成为企业、组织乃至整个社会发展的关键趋势。 信息技术的迅猛发展&#xff0c;如互联网、大数据、人工智能等&#xff0c;为数字化转型提供了强大支撑。市场竞争的加剧&#xff0c;也促使企业不断寻求提升竞争力的方法&#xff0c…

三小时快速上手TypeScript,TS速通教程(上篇、中篇、下篇、附加篇)

TypeScript速通 Typescript简介为什么需要TypeScriptJavaScript今非昔比JavaScript中的困扰1. 不清不楚的数据类型2. 有漏洞的逻辑3. 访问不存在的属性4. 低级的拼写错误 TypeScript静态类型检查 编译 TypeScript1. 命令行编译2. 自动化编译 类型声明类型推断类型总览JavaScrip…

敏感字段加密 - 华为OD统一考试(E卷)

2024华为OD机试(E卷+D卷+C卷)最新题库【超值优惠】Java/Python/C++合集 题目描述 【敏感字段加密】给定一个由多个命令字组成的命令字符串: 1、字符串长度小于等于127字节,只包含大小写字母,数字,下划线和偶数个双引号; 2、命令字之间以一个或多个下划线 进行分割; 3、可…

yakit使用教程(二,配置证书并进行抓包改包操作)

前文链接&#xff1a;yakit下载安装教程。 一&#xff0c;下载并配置证书。 点击mitm&#xff0c;在跳转后的页面点击高级配置。 点击证书下载。 点击下载到本地并打开&#xff08;建议下载到桌面&#xff09;。 在火狐浏览器下载并安装FoxyProxy&#xff0c;具体参数配置如上…

MATLAB在无线通信标准与协议支持中的作用

MATLAB是一款强大的数学计算和工程仿真软件&#xff0c;广泛应用于无线通信系统的设计、仿真和分析。它提供了一系列的工具箱&#xff0c;专门用于支持无线通信系统的标准和协议。本文将详细介绍MATLAB对无线通信系统标准和协议的支持&#xff0c;包括5G、Wi-Fi、LTE、卫星通信…

初始爬虫9

1.元素定位后的操作 “find_element“仅仅能够获取元素&#xff0c;不能够直接获取其中的数据&#xff0c;如果需要获取数据需要使用以下方法”。下面列出了两个方法&#xff1a; 获取文本 element.text 通过定位获取的标签对象的 text 属性&#xff0c;获取文本内容 获取属性…

一份冗长的文字

RS 名词 1.遥感 答案&#xff1a;从广义上说是泛指从远处探测、感知物体或事物的技术。即不直接接触物体本身&#xff0c;从远处通过仪器&#xff08;传感器&#xff09;探测和接收来自目标物体的信息&#xff08;如电场、磁场、电磁波、地震波等信息&#xff09;&#xff0c;…