扫一扫,分享给好友
说明: 为确保运行效果,本文及之后的文档示例都将以使用DevEco Studio 4.1 Beta1版本为例。
说明:
为确保运行效果,本文及之后的文档示例都将以使用DevEco Studio 4.1 Beta1版本为例。
我们在构建第一个应用程序中新建了一个名为MyApplication的项目,我们将在此项目上进行后续的开发。
在默认index.ets页面基础上,我们添加一个Button组件,作为按钮响应用户点击,从而实现跳转到另一个页面。Index.ets文件的示例如下:
// Index.ets @Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) // 添加按钮,以响应用户点击 Button() { Text('Next') .fontSize(30) .fontWeight(FontWeight.Bold) } .type(ButtonType.Capsule) .margin({ top: 20 }) .backgroundColor('#0D9FFB') .width('40%') .height('5%') } .width('100%') } .height('100%') } }
在编辑窗口右上角的侧边工具栏,点击Previewer,打开预览器。页面效果如下图所示:
编辑器窗口最下面的侧边工具栏中有日志和预览器日志选项(编辑器的中文化可参考DevEco Studio的使用-插件的安装),如下图示:
// index.ets @Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) // 添加按钮,以响应用户点击 Button() { Text('Next') .fontSize(30) .fontWeight(FontWeight.Bold) } .type(ButtonType.Capsule) .margin({ top: 20 }) .backgroundColor('#0D9FFB') .width('40%') .height('5%') .onClick(() => { console.log("Demo log: " + this.message) }) } .width('100%') } .height('100%') } }
// index.ets @Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) // 添加按钮,以响应用户点击 Button() { Text('Next') .fontSize(30) .fontWeight(FontWeight.Bold) } .type(ButtonType.Capsule) .margin({ top: 20 }) .backgroundColor('#0D9FFB') .width('40%') .height('5%') .onClick(() => { console.log("Demo log: " + this.message) }) } .width('100%') } .height('100%') }
发布
KaihongOS
多端协同主要应用场景介绍
KaihongOS笔记本电脑开发实战第九节:全功能TypeC驱动框架适配
开源鸿蒙开发新体验,开鸿Bot系列今日开启预售!
UIAbility组件生命周期介绍
UIAbility组件基本用法说明
UIAbility组件间交互(设备内)说明
UIAbility组件启动模式:实例在启动时的不同呈现状态
UIAbility组件与UI的数据同步介绍
KaihongOS操作系统:MQTT物联网通讯协议
在KaihongOS应用开发中,如何利用Socket进行数据传输
电子发烧友网
电子发烧友论坛