零基础学习鸿蒙开发,零基础学习鸿蒙App开发 (第一天)
最近發幾條質疑華鴻蒙系統的微頭條,受了很多網友的嘲笑,我準備零基礎自學App開發,我自己是運維,主要工作是維護Linux和Windows 服務器,同時兼桌面運維和網絡。
廢話不說,這是今天下午的成果。
安裝開發工具
創建項目
我不懂js ,只能選擇java作為開發語言
自動下載gradle
安裝SDK
配置模擬器,需要開發者帳戶,本人早有開發者帳號,這里不用申請 了。
運行默認的空項目
查看開發文檔,開發一個兩位數相加的計算器
邏輯非常簡單,xml里定義布局和幾個組件
1 x
2 y
3 result
4 button
在MainAbility.java中處理相關邏輯,即獲取 x y的值 相加并賦值給result
耗時3個小時完工
代碼如下: 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
總結
以上是生活随笔為你收集整理的零基础学习鸿蒙开发,零基础学习鸿蒙App开发 (第一天)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 毫秒比较_MYSQL的毫秒级
- 下一篇: php如何生成唯一随机数,PHP实现生成