从零开始学习HarmonyOS应用开发——1
1、首先安装必要的开发工具
1.1通过访问https://developer.harmonyos.com/cn/develop/deveco-studio
1.2安装软件
1.3通过访问https://nodejs.org/en/download/
(注:安装Node.js按自己系统安装)
1.4安装HarmonyOS SDK
把上述都勾选中进行安装。
2、创建一个HarmonyOS项目
选择EmptyAbility(选择框中的内容是,支持的设备)
下一步
3、实现最基础的页面跳转
3.1首先进入目录下的entry/src/main/resources/base/layout/下的ability_main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:alignment="center"ohos:orientation="vertical"><Textohos: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="$string:mainability_HelloWorld"ohos:text_size="40vp"/><Buttonohos:id="$+id:button1"ohos:height="match_parent"ohos:width="match_parent"ohos:layout_alignment="horizontal_center"ohos:text="跳转按钮"ohos:text_size="50vp"></Button></DirectionalLayout>
3.2然后去目录entry/src/main/java/com.example.helloword/slice/下的MainAbilitySlice文件:
package com.example.helloword.slice;import com.example.helloword.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;public class MainAbilitySlice extends AbilitySlice {@Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);Text text = (Text) findComponentById(ResourceTable.Id_text_helloworld);Button button = (Button) findComponentById(ResourceTable.Id_button1);/*注释:在找组件的过程中,系统会自己加上ID_,后面的部分为自己取的名字*/button.setClickedListener(listener->present(new SecondAbilitySlice(),new Intent()));}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}
}
3.3创建一个Slice在目录entry/src/main/java/com.example.helloword/slice/下新建一个java class取名为SecondAbilitySlice
SecondAbilitySlice文件为:
package com.example.helloword.slice;import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;public class SecondAbilitySlice extends AbilitySlice {@Overrideprotected void onStart(Intent intent) {super.onStart(intent);// 声明布局DependentLayout myLayout = new DependentLayout(this);// 设置布局宽高myLayout.setWidth(DependentLayout.LayoutConfig.MATCH_PARENT);myLayout.setHeight(DependentLayout.LayoutConfig.MATCH_PARENT);// 设置布局背景为白色ShapeElement background = new ShapeElement();background.setRgbColor(new RgbColor(255, 255, 255));myLayout.setBackground(background);// 创建一个文本Text text = new Text(this);text.setText("Hi there");text.setWidth(DependentLayout.LayoutConfig.MATCH_PARENT);text.setTextSize(100);text.setTextColor(Color.BLACK);// 设置文本的布局DependentLayout.LayoutConfig textConfig = new DependentLayout.LayoutConfig(DependentLayout.LayoutConfig.MATCH_CONTENT, DependentLayout.LayoutConfig.MATCH_CONTENT);textConfig.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);text.setLayoutConfig(textConfig);myLayout.addComponent(text);super.setUIContent(myLayout);}
}
3.4创建一个虚拟机
此处需要登陆,需要拥有开发者账号
选择手机(phone)
运行那个小三角就好了
4、结语
好的开始是成功的一大步!
从零开始学习HarmonyOS应用开发——1相关推荐
- 写给初学大数据的你,从零开始学习大数据开发的完整学习路线
最近很多人都想学习大数据开发,但是却不知道如何开始学习,今天专门整理了一份针对大数据初学者的大数据开发学习路线. 下面分十个章节来说明大数据开发要学习的内容: 互联网科技发展蓬勃兴起,人工智能时代来临 ...
- C#程序员的春天之从零开始学习unity3D游戏开发入门教程二(创建项目及基本面板介绍)...
一项目创建: 创建项目是开发的第一步. 运行untiy之后如果是第一次运行会弹出 我们这里随便创建一个项目. 二Untiy面板介绍: 三代码编辑器的切换: 这里我安装了vs2012. 到这里开发环境基 ...
- 从零开始学习C语言开发视频教程在线完整版
基本特性 1.C是高级语言:它是把高级语言的基本结构和语句与低级语言的实用性结合起来的工作单元. 2.C是结构式语言:结构式语言的显著特点是代码及数据的分隔化,即程序的各个部分除了必要的信息交流外彼此 ...
- 新手从零开始学习微信小程序开发01
新手从零开始学习小程序开发01 文章目录 新手从零开始学习小程序开发01 前言 一.什么是微信小程序? 二.如何着手学习微信小程序 1.开发工具下载安装 2.注册账户 前言 本章主要介绍微信小程序开发 ...
- harmonyos上的程序用什么语言写,HarmonyOS应用开发 — HelloWorld应用开发E2E体验
感谢关注HarmonyOS,为了便于大家学习特将鸿蒙2.0基础教学内容整理如下: 1.HarmonyOS应用开发-视频播放 https://developer.huawei.com/consumer/ ...
- HarmonyOS应用开发 — HelloWorld应用开发E2E体验
感谢关注HarmonyOS,为了便于大家学习特将鸿蒙2.0基础教学内容整理如下: 1.HarmonyOS应用开发-视频播放 https://developer.huawei.com/consumer/ ...
- HarmonyOS应用开发-剪切板
感谢关注HarmonyOS,为了便于大家学习特将鸿蒙2.0基础教学内容整理如下: 1.HarmonyOS应用开发-视频播放 https://developer.huawei.com/consumer/ ...
- HarmonyOS应用开发-基本控件
感谢关注HarmonyOS,为了便于大家学习特将鸿蒙2.0基础教学内容整理如下: 1.HarmonyOS应用开发-视频播放 https://developer.huawei.com/consumer/ ...
- 鸿蒙应用开发学习|HarmonyOS工程介绍
系列文章目录 第一章 HarmonyOS是什么 第二章 基础环境和开发工具 文章目录 系列文章目录 前言 一.HarmonyOS工程介绍 二.工程目录结构 三.工程目录介绍 1.entry 2.Abi ...
最新文章
- centos7 以上和以下版本设置
- 年度最期待游戏废土2登陆Linux
- linux读conf文件格式,CONF 文件扩展名: 它是什么以及如何打开它?
- 每周百万封业务邮件的服务器不知道为啥就down掉了?
- 2021最新H3CSE认证备考练习题,错过等明年!
- android toast居中显示_Android Toast 设置到屏幕中间,自定义Toast的实现方法,及其说明...
- 计算机网络安全员好就业吗,网络安全就业前景怎么样?
- JMeter做http接口功能测试
- phpspreadsheet文件下载
- 如何让iPad浏览器不再拒绝访问请求
- 《坂上之云》电影手记
- A类计算机机房温度变化,机房的温度、湿度标准值是多少 ?
- 文档型非关系数据库MongoDB经验总结
- googleplay刷榜和APP Store 刷榜哪些不为人知的事
- Android 指南针
- 陈一舟、开心网和域名事件
- Pandas两重山之Series(循环)
- 透明木头问世!“木头大王”胡良兵再发顶刊,已成立公司加速落地
- matlab怎样编程形成软件_matlab是什么编程语言?matlab是编程语言吗
- NASTRAN bdf介绍