微信上建微網(wǎng)站要錢嗎深圳seo優(yōu)化服務(wù)
1、首先安裝必要的開發(fā)工具
1.1通過訪問https://developer.harmonyos.com/cn/develop/deveco-studio
1.2安裝軟件
1.3通過訪問https://nodejs.org/en/download/
(注:安裝Node.js按自己系統(tǒng)安裝)
1.4安裝HarmonyOS SDK
把上述都勾選中進(jìn)行安裝。
2、創(chuàng)建一個(gè)HarmonyOS項(xiàng)目
選擇EmptyAbility(選擇框中的內(nèi)容是,支持的設(shè)備)
下一步
3、實(shí)現(xiàn)最基礎(chǔ)的頁面跳轉(zhuǎn)
3.1首先進(jìn)入目錄下的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="跳轉(zhuǎn)按鈕"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);/*注釋:在找組件的過程中,系統(tǒng)會(huì)自己加上ID_,后面的部分為自己取的名字*/button.setClickedListener(listener->present(new SecondAbilitySlice(),new Intent()));}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}
}
3.3創(chuàng)建一個(gè)Slice在目錄entry/src/main/java/com.example.helloword/slice/下新建一個(gè)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);// 設(shè)置布局寬高myLayout.setWidth(DependentLayout.LayoutConfig.MATCH_PARENT);myLayout.setHeight(DependentLayout.LayoutConfig.MATCH_PARENT);// 設(shè)置布局背景為白色ShapeElement background = new ShapeElement();background.setRgbColor(new RgbColor(255, 255, 255));myLayout.setBackground(background);// 創(chuàng)建一個(gè)文本Text text = new Text(this);text.setText("Hi there");text.setWidth(DependentLayout.LayoutConfig.MATCH_PARENT);text.setTextSize(100);text.setTextColor(Color.BLACK);// 設(shè)置文本的布局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創(chuàng)建一個(gè)虛擬機(jī)
此處需要登陸,需要擁有開發(fā)者賬號(hào)
選擇手機(jī)(phone)
運(yùn)行那個(gè)小三角就好了
4、結(jié)語
好的開始是成功的一大步!