赞
踩
1.鸿蒙开发软件目录结构
HarmonyOS的开发软件的目录
2.代码简介
config.json是核心配置文件
{
“app”: {
“bundleName”: “com.java.application”,
“vendor”: “java”,
“version”: {
“code”: 1000000,
“name”: “1.0.0”
}
},
“deviceConfig”: {},
“module”: {
“package”: “com.java.application”,
“name”: “.MyApplication”,
“mainAbility”: “com.java.application.MainAbility”,
“deviceType”: [
“phone”
],
“distro”: {
“deliveryWithInstall”: true,
“moduleName”: “entry”,
“moduleType”: “entry”,
“installationFree”: true
},
“abilities”: [
{
“skills”: [
{
“entities”: [
“entity.system.home”
],
“actions”: [
“action.system.home”
]
}
],
“orientation”: “unspecified”,
“name”: “com.java.application.MainAbility”,
“icon”: “
m
e
d
i
a
:
i
c
o
n
"
,
"
d
e
s
c
r
i
p
t
i
o
n
"
:
"
media:icon", "description": "
media:icon","description":"string:mainability_description”,
“label”: “$string:entry_MainAbility”,
“type”: “page”,
“launchType”: “standard”
}
]
}
}
其中,
app配置:
bundleName应用的唯一标识
version应用的版本。
module配置:用于声明当前应用的信息(包,类,主界面,功能模块声明,适配设备类型)
mainAbility声明当前应用启动时默认加载的Ability
mainAbilitySlice的代码如下:
package com.java.application.slice; import com.java.application.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; public class MainAbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); } } Layout_ability_main指向的ability_main.xml代码如下: ```xml <?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:height="match_parent" ohos:width="match_parent" ohos:alignment="center" ohos:orientation="vertical"> <Text ohos: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" /> </DirectionalLayout>
ability_main.xml代码mainability_HelloWorld指向
string.json中的代码:
{
“string”: [
{
“name”: “entry_MainAbility”,
“value”: “entry_MainAbility”
},
{
“name”: “mainability_description”,
“value”: “Java_Empty Ability”
},
{
“name”: “mainability_HelloWorld”,
“value”: “你好,世界”
}
]
}
然后就会显示“你好,世界”了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。