| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 37 | 34 | ||
| entry/ | 06-May-2025 | - | 1,286 | 1,116 | ||
| hvigor/ | 06-May-2025 | - | 23 | 22 | ||
| screenshots/devices/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 112 | 8 | 8 | |
| README.md | D | 06-May-2025 | 1,022 | 30 | 15 | |
| README_zh.md | D | 06-May-2025 | 2.1 KiB | 73 | 49 | |
| build-profile.json5 | D | 06-May-2025 | 1 KiB | 42 | 41 | |
| hvigorfile.ts | D | 06-May-2025 | 158 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2.1 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 72 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 815 | 26 | 25 | |
| ohosTest.md | D | 06-May-2025 | 1.2 KiB | 17 | 14 |
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 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 10|default主题|pomelo主题|simplicity主题| 11|---|---|---| 12|||| 13 14使用说明 15 161.点击顶部titleBar的右侧**切换**按钮,弹出主题菜单,选择任意主题则切换相应的主题界面; 17 182.退出应用再重新进入,显示上一次退出前的主题界面。 19 20### 工程目录 21``` 22entry/src/main/ets/ 23|---Application 24|---common 25| |---ThemeDesktop.ets // 首页主体内容 26|---MainAbility 27|---filemanager 28| |---data 29|---model // 日志文件 30|---pages 31| |---Index.ets // 首页,所有的接口和数据都封装在这里 32|---util 33| |---DataSource.ets // 数据懒加载 34``` 35 36### 具体实现 37 38* 切换主题:在首页预先设置好几套主体数据,使用preferences.getPreferences获取使用Preferences对象,调用Preferences.get() 39读取缓存中的参数,得到当前应该展示哪一套主体。每次点击切换按钮都会调用Preferences.put()来重新修改参数,然后使用 40Preferences.flush()保存并刷新文件内容。 41源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) 。 42 43### 相关权限 44 45不涉及。 46 47### 依赖 48 49不涉及。 50 51### 约束与限制 52 531. 本示例仅支持在标准系统上运行。 54 552. 本示例为Stage模型,从API version 9开始支持。 56 573. 本示例已适配API version 9版本SDK,版本号:3.2.11.9。 58 594. 本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400 构建 2023年4月7日)及以上版本才可编译运行。 60 61### 下载 62 63如需单独下载本工程,执行如下命令: 64 65``` 66git init 67git config core.sparsecheckout true 68echo code/BasicFeature/DataManagement/Preferences/ > .git/info/sparse-checkout 69git remote add origin https://gitee.com/openharmony/applications_app_samples.git 70git pull origin master 71``` 72 73