1e41f4b71Sopenharmony_ci# Resource Limitations and Access
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Resource Qualifiers
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciThe name of a resource qualifier consists of one or more qualifiers that represent the application scenarios or device characteristics, covering the screen density, and more. The qualifiers are separated using hyphens (-). When creating a qualifiers file under resources, you need to understand the file naming conventions and the rules for matching qualifiers files and the device status.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Naming Conventions for Resource Qualifiers
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci- Qualifiers are ordered in the following sequence: screen density. You can select one or multiple qualifiers to name your file based on your application scenarios and device characteristics, while following the preceding sequence. 
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci- The qualifiers are separated using hyphens (-), for example, res-dark-ldpi.json.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci- Value range of qualifiers: The value of each qualifier must meet the requirements specified in the following table. Otherwise, the resource files in the resources directory cannot be matched. The qualifiers are case sensitive.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci- Qualifier prefix: The name of a qualifier file in the resources file has the prefix res, for example, res-ldpi.json.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci- Default resource qualifier file: By default, the resource qualifier file in resources is res-defaults.json.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci- In the resource qualifier file, color enumeration cannot be used to set resources.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**Table 1** Resource qualifiers
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| Data Type | Description and Value Range |
27e41f4b71Sopenharmony_ci| -------- | -------- |
28e41f4b71Sopenharmony_ci| Screen density | Indicates the screen density of the device, in dpi. The value can be:<br/>- ldpi: low-density screen (\~120 dpi) (0.75 x Reference density)<br/>- mdpi: medium-density screen (\~160 dpi) (reference density)<br/>- hdpi: high-density screen (\~240 dpi) (1.5 x Reference density)<br/>- xhdpi: extra high-density screen (\~320 dpi) (2.0 x Reference density)<br/>- xxhdpi: extra extra high-density screen (\~480 dpi) (3.0 x Reference density)<br/>- xxxhdpi: extra extra extra high-density screen (\~640 dpi) (4.0 x Reference density) |
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci## Rules for Matching Qualifiers Files and Device Resources
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci- Qualifiers are matched with the device resources in the following priorities: screen orientation > dark mode > screen density. If no matching resource qualifier file is found, the default resource qualifier file is used.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci- If a qualifier file contains resource qualifiers, their values must be consistent with the current device status so that the file can be used for matching the device status. For example, the res-hdpi.json qualifier file does not match the device density xhdpi.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci## Referencing Resources in the JS Module
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ciYou can use the $r syntax in the application development files .hml and .js to format the JSON resources in the resources directory of the JS module and obtain the corresponding resources.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci| Attribute | Type | Description |
43e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
44e41f4b71Sopenharmony_ci| $r | (key: string) => string | Obtains the resource content that matches the specific qualifiers, for example, **this.$r('strings.hello loaded)**.<br/>Parameter description:<br/>- **key**: key value defined in the resource qualifier file, for example, **strings.hello**. |
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciExample of res-defaults.json:<br/>
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci```json
49e41f4b71Sopenharmony_ci{
50e41f4b71Sopenharmony_ci    "strings": {        
51e41f4b71Sopenharmony_ci        "hello": "hello world" 
52e41f4b71Sopenharmony_ci    }
53e41f4b71Sopenharmony_ci}
54e41f4b71Sopenharmony_ci```
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci## Example
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ciresources/res-dark.json:
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci```json
61e41f4b71Sopenharmony_ci{
62e41f4b71Sopenharmony_ci    "image": {
63e41f4b71Sopenharmony_ci        "clockFace": "common/dark_face.png"
64e41f4b71Sopenharmony_ci    },
65e41f4b71Sopenharmony_ci    "colors": {
66e41f4b71Sopenharmony_ci	"background": "#000000"
67e41f4b71Sopenharmony_ci    }
68e41f4b71Sopenharmony_ci}
69e41f4b71Sopenharmony_ci```
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciresources/res-defaults.json:
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci```json
74e41f4b71Sopenharmony_ci{
75e41f4b71Sopenharmony_ci    "image": {
76e41f4b71Sopenharmony_ci        "clockFace": "common/face.png"
77e41f4b71Sopenharmony_ci    },
78e41f4b71Sopenharmony_ci    "colors": {
79e41f4b71Sopenharmony_ci	"background": "#ffffff"
80e41f4b71Sopenharmony_ci    }
81e41f4b71Sopenharmony_ci}
82e41f4b71Sopenharmony_ci```
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci```html
85e41f4b71Sopenharmony_ci<!-- xxx.hml -->
86e41f4b71Sopenharmony_ci<div style="background-color: {{ $r('colors.background') }}">
87e41f4b71Sopenharmony_ci    <image src="{{ $r('image.clockFace') }}"></image>
88e41f4b71Sopenharmony_ci</div>
89e41f4b71Sopenharmony_ci```
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci> **NOTE**
92e41f4b71Sopenharmony_ci>
93e41f4b71Sopenharmony_ci> The resource qualifier file does not support color enumeration.
94