可能我被頭條的信息繭房困住了,一直出現(xiàn)鴻蒙的新聞,本人不是干手機(jī)APP開(kāi)發(fā)的,但出于好奇,就嘗試開(kāi)發(fā)一下。
首先去了鴻蒙官網(wǎng)
https://hmxt.org/下載了IDE,然后安裝了,跟著IDE的文檔生成了一個(gè)HelloWord工程。main_layout.xml
xmlns:ohos="
http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="match_parent"
ohos:background_element="#000000">
ohos:id="$+id:text"
ohos:width="match_content"
ohos:height="match_content"
ohos:center_in_parent="true"
ohos:text="HelloWorld"
ohos:text_color="white"
ohos:text_size="32fp"/>
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"/>
button_element.xml
xmlns:ohos="
http://schemas.huawei.com/res/ohos"
ohos:shape="oval">
ohos:color="#007DFF"/>
然后根據(jù)文檔寫(xiě)的,修改MainAbilitySlice.java文件
把onStart方法super.onStart(intent);下面的代碼都注釋掉,然后添加super.setUIContent(ResourceTable.Layout_main_layout);
但奇怪的是,ResourceTable里根本沒(méi)有Layout_main_layout這個(gè)常量,然后我就翻這個(gè)類(lèi),里面根本沒(méi)有。更奇怪的是,這個(gè)類(lèi)不在src目錄里,在這里
然后這程序咋的也不好使,教程也沒(méi)說(shuō)咋處理,我就隨便找了一個(gè)常亮放進(jìn)setUIContent里了,運(yùn)行了一次。右側(cè)的模擬器一閃就恢復(fù)了剛開(kāi)始的模樣,這時(shí)候,神奇的事情發(fā)生了,當(dāng)我再打開(kāi)這個(gè)類(lèi)的時(shí)候,里面多出來(lái)好多常量。。。。。。
以前的代碼是這樣
publicfinalclassResourceTable{
publicstaticfinalintMedia_icon=0x1000002;
publicstaticfinalintString_app_name=0x1000000;
publicstaticfinalintString_mainability_description=0x1000001;
后來(lái)就多出來(lái)幾個(gè)常量
publicfinalclassResourceTable{
publicstaticfinalintGraphic_button_element=0x1000003;
publicstaticfinalintId_button=0x1000005;
publicstaticfinalintId_text=0x1000006;
publicstaticfinalintLayout_main_layout=0x1000004;
publicstaticfinalintMedia_icon=0x1000002;
publicstaticfinalintString_app_name=0x1000000;
publicstaticfinalintString_mainability_description=0x1000001;
不知道這一步的操作是咋操作的,就運(yùn)行了一次錯(cuò)誤代碼就生成了,正規(guī)操作文檔里沒(méi)有介紹.......