HarmonyOS 鸿蒙Next:不同Product相同target如何加载不同的图片
HarmonyOS 鸿蒙Next:不同Product相同target如何加载不同的图片
Q1:
// 假设productA的full_screen_bg为一张 “春节图片”,productB的full_screen_bg为一张 “国庆节图片”
// 如何使该处的full_screen_bg 在productA中加载展示为 “春节图片”,在productB中加载为 “国庆节图片”
Image($r(‘app.media.full_screen_bg’))
Q2:
如何在不同product,相同target下使用不同的一套图标、图片资源
MyApplication
|-----AppScope
|-----entry
|------------src
|-------------------main
|-------------------------ets
|--------------------------------entryability
|--------------------------------------EntryAbility.ts
|--------------------------------pages
|--------------------------------------Index.ets
|-------------------------module.json5
|-------------build-profile.json5
|-----build-profile.json5
1: project(MyApplication)的build-profile.json5内容如下:
{
“app”: {
“signingConfigs”: [],
“compileSdkVersion”: 9,
“compatibleSdkVersion”: 9,
“products”: [
{
“name”: “default”,
“signingConfig”: “default”,
},
{
“name”: “productA”,
“bundleName”: “com.hm.aaa”,
“signingConfig”: “default”
},
{
“name”: “productB”,
“bundleName”: “com.hm.bbb”,
“signingConfig”: “default”,
}
]
},
“modules”: [
{
“name”: “entry”,
“srcPath”: “./entry”,
“targets”: [
{
“name”: “default”,
“applyToProducts”: [
“default”
]
},
// 生产环境
{
“name”: “product”,
“applyToProducts”: [
“productA”,
“productB”
]
},
// 测试环境
{
“name”: “beta”,
“applyToProducts”: [
“productA”,
“productB”
]
},
]
},
]
}
2: entry的build-profile.json5内容如下:
{
“apiType”: ‘stageMode’,
“buildOption”: {
},
“targets”: [
{
“name”: “default”,
“runtimeOS”: “HarmonyOS”
},
{
“name”: “ohosTest”,
},
{
“name”: “product”,
“runtimeOS”: “HarmonyOS”,
“config”: {
“deviceType”: [
“phone”
]
}
},
{
“name”: “beta”,
“runtimeOS”: “HarmonyOS”,
“config”: {
“deviceType”: [
“phone”
]
}
},
]
}
3: entry的module.json5内容如下:
{
“module”: {
“name”: “entry”,
“type”: “entry”,
“description”: “$string:module_desc”,
“mainElement”: “EntryAbility”,
“deviceTypes”: [
“phone”,
“tablet”
],
“deliveryWithInstall”: true,
“installationFree”: false,
“pages”: “$profile:main_pages”,
“abilities”: [
{
“name”: “EntryAbility”,
“srcEntry”: “./ets/entryability/EntryAbility.ts”,
“description”: “$string:EntryAbility_desc”,
“icon”: “$media:icon”,
“label”: “$string:EntryAbility_label”,
“startWindowIcon”: “$media:icon”,
“startWindowBackground”: “$color:start_window_background”,
“exported”: true,
“skills”: [
{
“entities”: [
“entity.system.home”
],
“actions”: [
“action.system.home”
]
}
]
},
]
}
}
4: entry的index.ets内容如下:
struct Index {
@State message: string = ‘Hello World s’
build() {
Row() {
Stack(){
// 假设productA的full_screen_bg为一张 “春节图片”,productB的full_screen_bg为一张 “国庆节图片”
// 如何使该处的full_screen_bg 在productA中加载展示为 “春节图片”,在productB中加载为 “国庆节图片”
Image($r(‘app.media.full_screen_bg’))
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width(‘100%’)
.height(‘100%’)
}
.height(‘100%’)
.width(‘100%’)
}
}
有推荐的方式吗?