可能我被头条的信息茧房困住了,一直出现鸿蒙的新闻,本人不是干手机APP开发的,但出于好奇,就尝试开发一下。
首先去了鸿蒙官网
https://hmxt.org/下载了IDE,然后安装了,跟着IDE的文档生成了一个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"/>
然后根据文档写的,修改MainAbilitySlice.java文件
把onStart方法super.onStart(intent);下面的代码都注释掉,然后添加super.setUIContent(ResourceTable.Layout_main_layout);
但奇怪的是,ResourceTable里根本没有Layout_main_layout这个常量,然后我就翻这个类,里面根本没有。更奇怪的是,这个类不在src目录里,在这里
然后这程序咋的也不好使,教程也没说咋处理,我就随便找了一个常亮放进setUIContent里了,运行了一次。右侧的模拟器一闪就恢复了刚开始的模样,这时候,神奇的事情发生了,当我再打开这个类的时候,里面多出来好多常量。。。。。。
以前的代码是这样
publicfinalclassResourceTable{
publicstaticfinalintMedia_icon=0x1000002;
publicstaticfinalintString_app_name=0x1000000;
publicstaticfinalintString_mainability_description=0x1000001;
后来就多出来几个常量
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;
不知道这一步的操作是咋操作的,就运行了一次错误代码就生成了,正规操作文档里没有介绍.......