鸿蒙开发——记第一次开发鸿蒙系统应用

可能我被头条的信息茧房困住了,一直出现鸿蒙的新闻,本人不是干手机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

main_layout.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>
button_element.xml
<?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;
}

不知道这一步的操作是咋操作的,就运行了一次错误代码就生成了,正规操作文档里没有介绍.......

文章标签里没鸿蒙,瞎选了一个安卓。

猜你喜欢

转载自blog.csdn.net/T262702247/article/details/108550941