Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
ca4b476c
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ca4b476c
编写于
6月 09, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 09, 2023
浏览文件
操作
浏览文件
下载
差异文件
!19273 增加color相关接口示例文档
Merge pull request !19273 from maoziduanl/master
上级
7be2ef30
cb708d18
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
381 addition
and
0 deletion
+381
-0
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md
...pplication-dev/reference/apis/js-apis-resource-manager.md
+381
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md
浏览文件 @
ca4b476c
...
...
@@ -3249,6 +3249,387 @@ getDrawableDescriptorByName(resName: string, density?: number): DrawableDescript
}
```
### getColor<sup>10+</sup>
getColor(resId: number, callback: AsyncCallback<number>): void;
用户获取指定资源ID对应的颜色值,使用callback形式返回其对应的颜色值。
**系统能力:** SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| resId | number | 是 | 资源ID值 |
| callback | AsyncCallback<number> | 是 | 异步回调,用于返回获取的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the module resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例Stage:**
```
ts
try {
this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let str = value;
}
});
} catch (error) {
console.error(
`callback getColor failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColor<sup>10+</sup>
getColor(resId: number): Promise<number>
用户获取指定资源ID对应的颜色值,使用Promise形式返回对应其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ----------- |
| Promise<number> | 资源ID值对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColor($r('app.color.test').id).then(value => {
let str = value;
}).catch(error => {
console.log("getColor promise error is " + error);
});
} catch (error) {
console.error(
`promise getColor failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColor<sup>10+</sup>
getColor(resource: Resource, callback: AsyncCallback<number>): void;
用户获取指定resource对象对应的颜色值,使用callback形式返回其对应的颜色值。
**系统能力:** SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| resource | [Resource](#resource9) | 是 | 资源信息 |
| callback | AsyncCallback<number> | 是 | 异步回调,用于返回获取的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.color.test').id
};
try {
this.context.resourceManager.getColor(resource, (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let str = value;
}
});
} catch (error) {
console.error(
`callback getColor failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColor<sup>10+</sup>
getColor(resource: Resource): Promise<number>;
用户获取指定resource对象对应的颜色值,使用Promise形式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是 | 资源信息 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise<number> | resource对象对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.color.test').id
};
try {
this.context.resourceManager.getColor(resource).then(value => {
let str = value;
}).catch(error => {
console.log("getColor promise error is " + error);
});
} catch (error) {
console.error(
`callback getColor failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColorByName<sup>10+</sup>
getColorByName(resName: string, callback: AsyncCallback<number>): void
用户获取指定资源名称对应的颜色值,使用callback形式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | --------------- |
| resName | string | 是 | 资源名称 |
| callback | AsyncCallback<number> | 是 | 异步回调,用于返回获取的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColorByName("test", (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let string = value;
}
});
} catch (error) {
console.error(
`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColorByName<sup>10+</sup>
getStringByName(resName: string): Promise<number>
用户获取指定资源名称对应的颜色值,使用Promise形式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ---------- |
| Promise<number> | 资源名称对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColorByName("test").then(value => {
let string = value;
}).catch(error => {
console.log("getColorByName promise error is " + error);
});
} catch (error) {
console.error(
`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColorSync<sup>10+</sup>
getColorSync(resId: number) : number;
用户获取指定资源ID对应的颜色值,使用同步方式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
**返回值:**
| 类型 | 说明 |
| ------ | ----------- |
| number | 资源ID值对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColorSync($r('app.color.test').id);
} catch (error) {
console.error(
`getColorSync failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColorSync<sup>10+</sup>
getColorSync(resource: Resource): number
用户获取指定resource对象对应的颜色值,使用同步方式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | 是 | 资源信息 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------------- |
| number | resource对象对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.color.test').id
};
try {
this.context.resourceManager.getColorSync(resource);
} catch (error) {
console.error(
`getColorSync failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getColorByNameSync<sup>10+</sup>
getColorByNameSync(resName: string) : number;
用户获取指定资源名称对应的颜色值,使用同步方式返回其对应的颜色值。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
**返回值:**
| 类型 | 说明 |
| ------ | ---------- |
| number | 资源名称对应的颜色值(十进制) |
**错误码:**
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
**示例:**
```
ts
try {
this.context.resourceManager.getColorByNameSync("test");
} catch (error) {
console.error(
`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getString<sup>(deprecated)</sup>
getString(resId: number, callback: AsyncCallback<string>): void
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录