From 189cdfd155ae03ffcb5c3f8bbda7ca7bf2358b1c Mon Sep 17 00:00:00 2001 From: huangjie Date: Wed, 30 Nov 2022 12:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E6=A1=A3=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangjie --- .../resource-categories-and-access.md | 52 +++++++++++-------- .../apis/js-apis-resource-manager.md | 16 +++--- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/zh-cn/application-dev/quick-start/resource-categories-and-access.md b/zh-cn/application-dev/quick-start/resource-categories-and-access.md index 028d88e440..e71e9904c0 100644 --- a/zh-cn/application-dev/quick-start/resource-categories-and-access.md +++ b/zh-cn/application-dev/quick-start/resource-categories-and-access.md @@ -230,28 +230,27 @@ plural.json文件的内容如下: > > `$r`返回值为Resource对象,可通过[getStringValue](../reference/apis/js-apis-resource-manager.md#getstringvalue9) 方法获取对应的字符串。 -在xxx.ets文件中,可以使用在resources目录中定义的资源。 +在xxx.ets文件中,可以使用在resources目录中定义的资源。结合[资源组目录](#资源组目录)中的“资源文件示例”,资源使用示例如下: ```ts Text($r('app.string.string_hello')) - .fontColor($r('app.color.color_hello')) - .fontSize($r('app.float.font_hello')) -} + .fontColor($r('app.color.color_hello')) + .fontSize($r('app.float.font_hello')) Text($r('app.string.string_world')) - .fontColor($r('app.color.color_world')) - .fontSize($r('app.float.font_world')) -} + .fontColor($r('app.color.color_world')) + .fontSize($r('app.float.font_world')) -Text($r('app.string.message_arrive', "five of the clock")) // 引用string资源,$r的第二个参数用于替换%s - .fontColor($r('app.color.color_hello')) - .fontSize($r('app.float.font_hello')) -} +// 引用string.json资源,$r的第二个参数用于替换%s,value为"We will arrive at five of the clock"。 +Text($r('app.string.message_arrive', "five of the clock")) + .fontColor($r('app.color.color_hello')) + .fontSize($r('app.float.font_hello')) -Text($r('app.plural.eat_apple', 5, 5)) // plural$r引用,第一个指定plural资源,第二个参数指定单复数的数量,此处第三个数字为对%d的替换 - .fontColor($r('app.color.color_world')) - .fontSize($r('app.float.font_world')) -} +// 引用plural$资源,第一个指定plural资源,第二个参数指定单复数的数量quantity,此处第三个数字为对%d的替换 +// 单数下value为"5 apple",复数下value为"5 apples"。 +Text($r('app.plural.eat_apple', 5, 5)) + .fontColor($r('app.color.color_world')) + .fontSize($r('app.float.font_world')) Image($r('app.media.my_background_image')) // media资源的$r引用 @@ -277,15 +276,22 @@ Image($rawfile('newDir/newTest.png')) // rawfile$r引用rawfile目录下 ```ts Text('Hello') - .fontColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize($r('sys.float.ohos_id_text_size_headline1')) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) + .fontColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize($r('sys.float.ohos_id_text_size_headline1')) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .backgroundColor($r('sys.color.ohos_id_color_palette_aux1')) + Image($r('sys.media.ohos_app_icon')) - .border({color: $r('sys.color.ohos_id_color_palette_aux1'), radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2}) - .margin({top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l')}) - .height(200) - .width(300) + .border({ + color: $r('sys.color.ohos_id_color_palette_aux1'), + radius: $r('sys.float.ohos_id_corner_radius_button'), width: 2 + }) + .margin({ + top: $r('sys.float.ohos_id_elements_margin_horizontal_m'), + bottom: $r('sys.float.ohos_id_elements_margin_horizontal_l') + }) + .height(200) + .width(300) ``` ## 相关实例 diff --git a/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md b/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md index 33144a5658..d71b3bb4e2 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-resource-manager.md @@ -15,7 +15,7 @@ import resourceManager from '@ohos.resourceManager'; ## 使用说明 -从API Version9开始,Stage模型支持了通过context获取resourceManager对象的方式,再调用其内部获取资源的接口,无需再导入包,此方式FA模型不适用。 +从API Version9开始,Stage模型通过context获取resourceManager对象的方式后,可直接调用其内部获取资源的接口,无需再导入包。此方式FA模型不适用,FA模型还需要先导入包,再调用[getResourceManager](#resourcemanagergetresourcemanager)接口获取资源对象。 Stage模型下Context的引用方法请参考[Stage模型的Context详细介绍](../../ability/context-userguide.md) ```ts @@ -305,7 +305,7 @@ getStringValue(resId: number, callback: AsyncCallback<string>): void **示例Stage:** ```ts try { - this.context.getStringValue($r('app.string.test').id, (error, value) => { + this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => { if (error != null) { console.log("error is " + error); } else { @@ -2495,7 +2495,7 @@ getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void 用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。 -从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent)代替。 +从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9)代替。 **系统能力**:SystemCapability.Global.ResourceManager @@ -2526,7 +2526,7 @@ getMedia(resId: number): Promise<Uint8Array> 用户获取指定资源ID对应的媒体文件内容,使用Promise形式返回字节数组。 -从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent-1)代替。 +从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9-1)代替。 **系统能力**:SystemCapability.Global.ResourceManager @@ -2559,7 +2559,7 @@ getMediaBase64(resId: number, callback: AsyncCallback<string>): void 用户获取指定资源ID对应的图片资源Base64编码,使用callback形式返回字符串。 -从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase64)代替。 +从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase649)代替。 **系统能力**:SystemCapability.Global.ResourceManager @@ -2590,7 +2590,7 @@ getMediaBase64(resId: number): Promise<string> 用户获取指定资源ID对应的图片资源Base64编码,使用Promise形式返回字符串。 -从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase64-1)代替。 +从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase649-1)代替。 **系统能力**:SystemCapability.Global.ResourceManager @@ -2623,7 +2623,7 @@ getPluralString(resId: number, num: number): Promise<string> 根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串。 -从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue)代替。 +从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9)代替。 **系统能力**:SystemCapability.Global.ResourceManager @@ -2657,7 +2657,7 @@ getPluralString(resId: number, num: number, callback: AsyncCallback<string> 根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。 -从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue-1)代替。 +从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9-1)代替。 **系统能力**:SystemCapability.Global.ResourceManager -- GitLab