可能我被頭條的資訊繭房困住了,一直出現鴻蒙的新聞,本人不是干手機APP開發的,但出于好奇,就嘗試開發一下,
首先去了鴻蒙官網 https://hmxt.org/ 下載了IDE,然后安裝了,跟著IDE的檔案生成了一個Hello Word工程,
這是檔案
https://developer.harmonyos.com/cn/docs/documentation/doc-guides/hello_world-0000001054516888

然后根據入門檔案撰寫第一個XML頁面

首先在工程目錄下創建2個檔案夾layout、graphic 和兩個xml main_layout.xml、button_element.xml

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="match_parent"
ohos:background_element="#000000">
<Text
ohos:id="$+id:text"
ohos:width="match_content"
ohos:height="match_content"
ohos:center_in_parent="true"
ohos:text="Hello World"
ohos:text_color="white"
ohos:text_size="32fp"/>
<Button
ohos:id="$+id:button"
ohos:width="match_content"
ohos:height="match_content"
ohos:text_size="19fp"
ohos:text="Next"
ohos:top_padding="8vp"
ohos:bottom_padding="8vp"
ohos:right_padding="80vp"
ohos:left_padding="80vp"
ohos:text_color="white"
ohos:background_element="$graphic:button_element"
ohos:center_in_parent="true"
ohos:align_parent_bottom="true"/>
</DependentLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="oval">
<solid
ohos:color="#007DFF"/>
</shape>
然后根據檔案寫的,修改MainAbilitySlice.java檔案
把onStart方法 super.onStart(intent); 下面的代碼都注釋掉,然后添加 super.setUIContent(ResourceTable.Layout_main_layout);
但奇怪的是,ResourceTable里根本沒有Layout_main_layout這個常量,然后我就翻這個類,里面根本沒有,更奇怪的是,這個類不在src目錄里,在這里

然后這程式咋的也不好使,教程也沒說咋處理,我就隨便找了一個常亮放進setUIContent里了,運行了一次,右側的模擬器一閃就恢復了剛開始的模樣,這時候,神奇的事情發生了,當我再打開這個類的時候,里面多出來好多常量,,,,,,
以前的代碼是這樣
public final class ResourceTable {
public static final int Media_icon = 0x1000002;
public static final int String_app_name = 0x1000000;
public static final int String_mainability_description = 0x1000001;
}
后來就多出來幾個常量
public final class ResourceTable {
public static final int Graphic_button_element = 0x1000003;
public static final int Id_button = 0x1000005;
public static final int Id_text = 0x1000006;
public static final int Layout_main_layout = 0x1000004;
public static final int Media_icon = 0x1000002;
public static final int String_app_name = 0x1000000;
public static final int String_mainability_description = 0x1000001;
}
不知道這一步的操作是咋操作的,就運行了一次錯誤代碼就生成了,正規操作檔案里沒有介紹.......
文章標簽里沒鴻蒙,瞎選了一個安卓,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/38191.html
標籤:其他
