ToB企服应用市场:ToB评测及商务社交产业平台
标题:
HarmonyOS APP 开发入门
[打印本页]
作者:
杀鸡焉用牛刀
时间:
2022-6-24 00:55
标题:
HarmonyOS APP 开发入门
前言
HarmonyOS官方定义
鸿蒙是一个全场景,面向未来的操作系统。
解释:
鸿蒙并不是一个单纯的手机操作系统,而是手机 + 智能设备的总称。可以安装在包括手机、手表、无人机等很多 设备上。
鸿蒙分为两类:
应用开发:也是整个鸿蒙的控制中心。(手机app)
开发语言:Java,js,C/C++(华为目前建议使用的还是Java)
内核:基于Linux内核开发的
设备开发:也就是无人机,摄像机等硬件设备。最合适的开发语言:C/C++
一、 安装鸿蒙编译器 --DevEco Studio
1.适合开发鸿蒙的语言
Java,C/C++,JavaScript,eTS,cangjie(仓颉)
Java,js适合手机应用的开发
C/C++适用于硬件开发
在以后的鸿蒙版本中(华为计划是3.0),即将推出仓颉语言开发。(已经开始内测,还没可以使用)
复制代码
但是就目前而言,华为主推的还是Java。
2.鸿蒙开发的完整流程
3.Java开发的准备工作
1)注册开发者(略)
2)下载开发工具
DevEco Studio就是鸿蒙应用开发的开发工具,是基于IntelliJ IDEA Community开源版本打造的,所以如果大家有 idea的基础,在学习DevEco Studio是非常容易上手的。
DevEco Studio中提供SDK Manager统一管理SDK和这个包依赖的工具链。通过SDK Manager能自动下载各个语 言对应的SDK包。
4)下载网址:
HarmonyOS
5)版本说明
DevEco Studio 1.0 用于华为EMUI系统的应用App。
DevEco Studio 2.0 用于华为鸿蒙系统(HarmonyOS)的应用App。
DevEco Studio 3.0 用于华为鸿蒙系统(openHarmonyOS)的应用App。
4)使用Java开发
JDK:是Java语言所需要的开发环境。鸿蒙开发工具DevEco Studio会帮我们自动下载。
!!!
鸿蒙开发工具目前只支持JDK8
。
5)常用插件
Toolchains:SDK工具链,HarmonyOS应用开发必备工具集,包括编译、打包、签名、数据库管理等工具的集 合,首次下载SDK时默认下载。
Previewer:Lite Wearable预览器,在开发过程中可以动态预览Lite Wearable应用的界面呈现效果,默认不自 动下载,需手动勾选下载。
6)安装开发工具
傻瓜式安装–略
4.DevEco Studio项目结构(Java)
MyApplication:整个项目的项目名
External Libraries:项目中要导入的第三方jar包
.gradle:是项目管理工具gradle的信息(一般是不会动)
.idea:是开发工具的信息(一般不会动)
entry:是应用主模块,在一个项目中,有且只有一个,所有的代码都在这个里面。(重要)
gradle:项目管理工具gradle的配置信息和所需要用到的jar包,在这个里面有一个porperties的配置文件, 可以看到gradle的版本号,一般我们会用默认的,也不会动
build.gradle:第三方jar包的配置文件,以后在开发中要用到第三方jar包需要在这个里面配置。
build.gradle:第三方jar包的配置文件,以后在开发中要用到第三方jar包需要在这个里面配置。(一个是linux系统的,一个是windows系统的。)
local.properties:本地SDK配置信息,一般也不动。
build:一般不会动,这个文件夹里面有一个R文件,记录每一个资源文件对应的id。里面的内容是自动生成的。(R文件是一个压缩包,里面装的ResourceTable这个类的字节码文件。)
libs:第三方jar包存放的位置
src:主要代码(src里面还有三个目录,main,ohosTest,test)
src里面还有三个目录
src里面还有三个目录
test:是Junit的测试工具。
二、第一个HarmonyOS项目(官方教程解析)
1.第一个Harmony入门应用HelloWorld
对于Helloworld,相信大家都不会陌生,我们学习大部分语言的时候,所做的第一个项目就是HelloWorld。
当我们新建第一个项目的时候,我们的Studio就会自己生成一个HelloWorld项目,这也是我们正式入门HarmonyOS APP移动开发的第一个项目。
对于这个项目,我们需要了解的知识点只有四个
1、如何运行项目
2、页面中的包含关系
3、配置文件:confifig.json
4、了解程序的启动流程
2.运行项目
要运行项目就需要我们去登录我们的华为开发者账号,点击Studio右上角的登录按钮登录即可
要运行项目,我们就需要使用到模拟器来运行项目,华为官方为我们提供了两种模拟器,一种是本地模拟器,一种是在线模拟器,我们将使用在线模拟器来讲解。
点击工具(tools)下的Device Manger,进入如图所示页面
在这里我们选择Remote Emulator,选择需要的手机型号,点击绿色的三角形就行启动模拟器
这里需要注意,我们这里的API与我们所安装的HarmonyOS SDK 是息息相关的,如果你没有安装对应版本的SDK那么程序就会运行错误
3. 页面中的包含关系
MainAbility是项目启动的第一个界面,在界面里面不是直接显示内容的。在界面里面展示的是子界面,我们也称之为切片,或者片 段,在子界面里面才是显示内容。
如图所示,MainAbility是我们第一个所展示的页面,MainAbilitySlice就是一个子页面,而我们的内容只能在子页面里展现出来。
MainAbility (界面)
包含
一个或多个MainAbilitySlice(子界面)
MainAbilitySlice(子界面)
包含
要显示的内容
4.配置文件:config.json
config.json 是整个APP项目的配置文件。所有项目信息都会配置在这里,如,版本号,厂商信息等
5.程序运行过程
6.实现页面跳转
通过代码实现以下操作
设计步骤:
1. 设置页面文本内容,按钮组件
2. 设置第二个页面内容
3. 设置时间进行跳转
复制代码
下面先来对Layout下的xml文件进行编辑
补充知识:
在MainAbilitySlice.java里
如图,ResourceTable.Layout_ability_main表示的是在resource下有一个叫ability_main.xml的文件,这个文件是我们的主页面,HarmonyOS的app开发是通过xml来进行页面设计的。
下面我们正式开始进行编程解决这个问题
ability_main.xml
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>
复制代码
下面需要建立一个新的切片
选择slice包,右键
我们选择新建>Ability >Empty Page Ability(Java)
在这里我们就可以新建切片了,不要选择图中的Launcher ability,否则它就会变成我们的主页面了
我们在HarmonyOS开发里,有两种布局方式,一种是xml,一种是直接用java进行编写,在这里,我们第二个页面通过Java编写
cyy__two_AbilitySlice.java
package com.itcyy.myapplication.slice;import com.itcyy.myapplication.ResourceTable;import ohos.aafwk.ability.AbilitySlice;import ohos.aafwk.content.Intent;import ohos.agp.components.DirectionalLayout;import ohos.agp.components.Text;import ohos.agp.utils.Color;public class cyy_two_AbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.onStart(intent);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//super.setUIContent(ResourceTable.Layout_ability_cyy_two_);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//1.创建一个布局对象<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>DirectionalLayout dl = new DirectionalLayout(this);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//2.创建一个文本对象<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>Text t = new Text(this);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//设置内容<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>t.setText("cyy第二个页面");<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//设置大小<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>t.setTextSize(55);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//设置文本颜色<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>t.setTextColor(Color.BLUE);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//将文本对象加入布局中<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>dl.addComponent(t);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//4.把创建的布局加入到子页面中<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.setUIContent(dl); } @Override public void onActive() {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.onActive(); } @Override public void onForeground(Intent intent) {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.onForeground(intent); }}
复制代码
MainAbilitySlice.java
package com.itcyy.myapplication.slice;import com.itcyy.myapplication.ResourceTable;import ohos.aafwk.ability.AbilitySlice;import ohos.aafwk.content.Intent;import ohos.aafwk.content.Operation;import ohos.agp.components.Button;import ohos.agp.components.Component;public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener { Button cyy_button; @Override public void onStart(Intent intent) {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.onStart(intent);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.setUIContent(ResourceTable.Layout_ability_main);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//1.通过id寻找创建的按钮<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//Button cyy_button = (Button)findComponentById(ResourceTable.Id_cyy_one_button);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>cyy_button = (Button)findComponentById(ResourceTable.Id_cyy_one_button);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//2.给按钮添加一个点击事件<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//如果按钮没有添加点击事件,那么点击按钮将不会有任何反应<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//如果我们给按钮添加了点击事件的话,那么我们点击按钮之后就会执行相应的代码<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//当我们点击了cyy_button这个按钮之后,那么就会实现本类的onClick方法<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>cyy_button.setClickedListener(this);//注意这里是需要继承Component.ClickedListener接口的 } @Override public void onActive() {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.onActive(); } @Override public void onForeground(Intent intent) {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>super.onForeground(intent); } @Override public void onClick(Component component) {<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//点击按钮需要执行的代码<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>//跳转到第二个页面<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>if (component == cyy_button){<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> //只有点击了cyy_button 这个按钮后才进行跳转<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> //跳转到哪个页面(意图)<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> //创建意图对象<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> Intent i = new Intent();<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> //包含了要跳转页面的详细信息<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> Operation operation = new Intent.OperationBuilder()<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout><?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> .withDeviceId("")//要跳转到哪个设备上,如果传递一个空字符串,则表示跳转到本机<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout><?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> .withBundleName("com.itcyy.myapplication")//要跳转到哪个应用上,小括号里可写包名<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout><?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> .withAbilityName("com.itcyy.myapplication.cyy_two_Ability")//要跳转到哪个页面,小括号填写包名<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout><?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> .build();//将上面三个信息打包<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> //把打包之后的operation对象传到意图里<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> i.setOperation(operation);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> //跳转页面<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout> startAbility(i);<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="itcyy第一个页面"
ohos:text_size="40vp"
/>
<Button
ohos:id="$+id:cyy_one_button"
ohos:height="match_content"
ohos:width="match_content"
ohos:text_size="40fp"
ohos:background_element="red"
ohos:text="点我"/>
</DirectionalLayout>} }}
复制代码
看下效果
喜欢本博文的可以关注一下Gun尘心,以后会持续更新关于HarmonyOS APP 开发的基础知识的
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4