当前位置:   article > 正文

鸿蒙开发应用_$r('') 鸿蒙

$r('') 鸿蒙

1.鸿蒙开发软件目录结构
HarmonyOS的开发软件的目录在这里插入图片描述
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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

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”: “你好,世界”
}
]
}
然后就会显示“你好,世界”了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/338815
推荐阅读
相关标签
  

闽ICP备14008679号