• Home
Name Date Size #Lines LOC

..--

AppScope/12-May-2024-3734

entry/12-May-2024-1,2871,117

hvigor/12-May-2024-2322

screenshots/devices/12-May-2024-

.gitignoreD12-May-2024112 88

README.mdD12-May-20241,022 3015

README_zh.mdD12-May-20242.1 KiB7248

build-profile.json5D12-May-20241 KiB4241

hvigorfile.tsD12-May-2024158 21

hvigorwD12-May-20242.1 KiB6228

hvigorw.batD12-May-20242 KiB7256

oh-package.json5D12-May-2024815 2625

ohosTest.mdD12-May-20241.2 KiB1714

README.md

1#  Preferences
2
3### Introduction
4
5This sample shows how to alternate between themes using preferences. The display effect is as follows:
6
7![](screenshots/devices/default_en.png)
8
9### Concepts
10
11Preferences: provide capabilities for processing data in the form of key-value (KV) pairs and support lightweight data persistence, modification, and query. In KV pairs, the keys are of the string type, and the values can be of the number, string, Boolean, Array\<number>, Array\<string>, or Array\<boolean> type.
12
13### Required Permissions
14
15N/A.
16
17### Usage
18
191. Touch the switch button on the upper right corner of the title bar, and select the target theme from the screen displayed.
20
212. Exit the app and then access it again. The theme before the last exit is displayed.
22
23### Constraints
24
25- This sample can only be run on standard-system devices.
26
27- This sample is based on the stage model, which is supported from API version 9.
28
29- This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100) to compile and run.
30

README_zh.md

1#  首选项
2
3### 简介
4
5本示例使用[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md)接口,展示了使用首选项持久化存储数据的功能。
6
7### 效果预览
8
9|default主题|pomelo主题|simplicity主题|
10|---|---|---|
11|![](screenshots/devices/default.png)|![](screenshots/devices/pomelo.png)|![](screenshots/devices/simplicity.png)|
12
13使用说明
14
151.点击顶部titleBar的右侧**切换**按钮,弹出主题菜单,选择任意主题则切换相应的主题界面;
16
172.退出应用再重新进入,显示上一次退出前的主题界面。
18
19### 工程目录
20```
21entry/src/main/ets/
22|---Application
23|---common
24|   |---ThemeDesktop.ets      // 首页主体内容
25|---MainAbility
26|---filemanager
27|   |---data
28|---model                     // 日志文件
29|---pages
30|   |---Index.ets             // 首页,所有的接口和数据都封装在这里
31|---util
32|   |---DataSource.ets        // 数据懒加载
33```
34
35### 具体实现
36
37* 切换主题:在首页预先设置好几套主体数据,使用preferences.getPreferences获取使用Preferences对象,调用Preferences.get()
38读取缓存中的参数,得到当前应该展示哪一套主体。每次点击切换按钮都会调用Preferences.put()来重新修改参数,然后使用
39Preferences.flush()保存并刷新文件内容。
40源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) 。
41
42### 相关权限
43
44不涉及。
45
46### 依赖
47
48不涉及。
49
50### 约束与限制
51
521. 本示例仅支持在标准系统上运行。
53
542. 本示例为Stage模型,从API version 9开始支持。
55
563. 本示例已适配API version 9版本SDK,版本号:3.2.11.9。
57
584. 本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400 构建 2023年4月7日)及以上版本才可编译运行。
59
60### 下载
61
62如需单独下载本工程,执行如下命令:
63
64```
65git init
66git config core.sparsecheckout true
67echo code/BasicFeature/DataManagement/Preferences/ > .git/info/sparse-checkout
68git remote add origin https://gitee.com/openharmony/applications_app_samples.git
69git pull origin master
70```
71
72