提交 189cdfd1 编写于 作者: H huangjie

资源文档维护

Signed-off-by: Nhuangjie <huangjie125@huawei.com>
上级 3d8561d8
......@@ -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'))
}
Text($r('app.string.string_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
// 引用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的替换
// 引用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引用
......@@ -281,9 +280,16 @@ Text('Hello')
.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')})
.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)
```
......
......@@ -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&lt;string&gt;): 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&lt;Uint8Array&gt;): void
用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。
从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent)代替。
从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9)代替。
**系统能力**:SystemCapability.Global.ResourceManager
......@@ -2526,7 +2526,7 @@ getMedia(resId: number): Promise&lt;Uint8Array&gt;
用户获取指定资源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&lt;string&gt;): 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&lt;string&gt;
用户获取指定资源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&lt;string&gt;
根据指定数量获取对指定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&lt;string&gt
根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。
从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue-1)代替。
从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9-1)代替。
**系统能力**:SystemCapability.Global.ResourceManager
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册