鸿蒙 app开发,零基础学习鸿蒙App开发 (第一天)

最近发几条质疑华鸿蒙系统的微头条,受了很多网友的嘲笑,我准备零基础自学App开发,我自己是运维,主要工作是维护Linux和Windows 服务器,同时兼桌面运维和网络。

废话不说,这是今天下午的成果。

安装开发工具

210452661_1_2020121909342971

210452661_2_20201219093429149

210452661_3_20201219093429243

210452661_4_20201219093429305

210452661_5_20201219093429384

创建项目

210452661_6_20201219093429509

210452661_7_20201219093429604

我不懂js ,只能选择java作为开发语言

210452661_8_20201219093429680

自动下载gradle

210452661_9_20201219093429759

安装SDK

210452661_10_20201219093429868

210452661_11_20201219093429946

210452661_12_2020121909343040

配置模拟器,需要开发者帐户,本人早有开发者帐号,这里不用申请 了。

210452661_13_20201219093430134

210452661_14_20201219093430305

210452661_15_20201219093430384

210452661_16_20201219093430462

运行默认的空项目

210452661_17_20201219093430555

210452661_18_20201219093430649

查看开发文档,开发一个两位数相加的计算器

逻辑非常简单,xml里定义布局和几个组件

1 x

2 y

3 result

4 button

在MainAbility.java中处理相关逻辑,即获取 x y的值 相加并赋值给result

210452661_19_20201219093430759

210452661_20_20201219093430837

210452661_21_202012190934319

210452661_22_20201219093431134

耗时3个小时完工

210452661_23_20201219093431290

代码如下: ability_main.xml

MainAbility.javapackage com.example.demo;import com.example.demo.slice.MainAbilitySlice;import ohos.aafwk.ability.Ability;import ohos.aafwk.content.Intent;import ohos.agp.components.Button;import ohos.agp.components.Component;import ohos.agp.components.Text;import ohos.agp.components.TextField;public class MainAbility extends Ability{ @Override public void onStart(Intent intent){ super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); super.setMainRoute(MainAbilitySlice.class.getName()); Button button_add = (Button) findComponentById(ResourceTable.Id_add); button_add.setClickedListener(new Component.ClickedListener(){ @Override public void onClick(Component component){ TextField text_x = (TextField) findComponentById(ResourceTable.Id_x); int x = Integer.parseInt(text_x.getText()); TextField text_y = (TextField) findComponentById(ResourceTable.Id_y); int y = Integer.parseInt(text_y.getText()); int result = x + y; TextField text_result = (TextField) findComponentById(ResourceTable.Id_result); text_result.setText(String.valueOf(result)); System.out.println(result); } }); } @Override public void onActive(){ super.onActive(); } @Override public void onForeground(Intent intent){ super.onForeground(intent); }}

明天做好签名准备打包hap

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值