当前位置: 首页 > news >正文

江门网站制作公司seo软件安卓版

江门网站制作公司,seo软件安卓版,wordpress设置中改网站,邯郸推广公司Harmonyos之换肤功能 概述实现原理颜色适配颜色资源配置工具类编写界面代码编写适配效果 概述 深色模式(Dark Mode)又称之为暗色模式,是与日常应用使用过程中的浅色模式(Light Mode)相对应的一种UI主题。 换肤功能应…

Harmonyos之换肤功能

  • 概述
  • 实现原理
  • 颜色适配
    • 颜色资源配置
    • 工具类编写
    • 界面代码编写
    • 适配效果

概述

深色模式(Dark Mode)又称之为暗色模式,是与日常应用使用过程中的浅色模式(Light Mode)相对应的一种UI主题。

换肤功能应该是现在APP常见的一个功能, 现在我们来了解下载Harmonyos上app是如何实现换肤功能的。

实现原理

当系统切换到深色模式后,应用内可能会出现部分内容切换到深色主题的情况,例如状态栏、弹窗背景色、系统控件等,会导致应用内页面效果错乱。

为应对上述情况,需要对应用进行深色模式下的内容适配,目前该适配主要依靠资源目录。当系统对应的设置项发生变化后(如系统语言、深浅色模式等),应用会自动加载对应资源目录下的资源文件。

创建的项目默认是支持浅色模式的, 资源一般都放在src/main/resources/base目录下的,如下图:
在这里插入图片描述
但是系统为深色模式预留了dark目录,该目录在应用创建时默认不存在,在进行深色模式适配时,需要开发者在src/main/resources中手动地创建出dark目录,将深色模式所需的资源放置到该目录下。
在这里插入图片描述

说明
在进行资源定义时,需要在base目录与dark目录中定义同名的资源。例如在base/element/color.json文件中定义text_color为黑色,在dark/element/color.json文件中定义text_color为白色,那么当深浅色切换时,应用内使用了$('app.color.text_color ')作为颜色值的元素会自动切换到对应的颜色,而无需使用其他逻辑判断进行控制。

颜色适配

颜色资源配置

对于颜色资源的适配, 目前有两种方式:

  • 使用系统资源, 当系统切换模式时, 使用受支持的系统资源会自动适配深浅模式。开发人员可以查看支持的系统资源
  • 使用自定义的主题,那么就需要配置不同主题的颜色资源。

这里以配置自定义主题来适配颜色:

配置浅色模式的颜色资源, 配置目录src/main/resources/base/element/color.json

{"color": [// 浅色主题的颜色{"name": "test_skin","value": "#008000"}]
}

配置深色模式, 配置目录src/main/resources/dark/element/color.json

{"color": [// 深色主题颜色{"name": "test_skin","value": "#FFFF00"}]
}

工具类编写

AppSkinManager工具类的编写:

import { appPreferences } from './AppPreferences'
import { ConfigurationConstant } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
import { BusinessError } from '@ohos.base';
import { JSON } from '@kit.ArkTS';const TAG = "AppSkinManager"
export enum AppSkinMode {// 未设置  跟随系统NOT_SET,// 白色LIGHT,// 黑色DARK
}export class AppSkinManager {// 当前皮肤色, 默认没有设置skinMode: AppSkinMode = AppSkinMode.NOT_SET;private SKIN_KEY: string = 'skinMode'// 判断当前是否是黑板static isDartMode(mode: AppSkinMode) {return mode === AppSkinMode.DARK;}// 初始化方法public init() {// 初始化黑白版this.skinMode = appPreferences.getSync(this.SKIN_KEY, AppSkinMode.NOT_SET) as number;console.log(`shinMode get from file is ${this.skinMode}`);}// 更换皮肤public changeSkin(context: Context, mode: AppSkinMode) {if (this.skinMode !== mode) {this.skinMode = mode;appPreferences.putSync(this.SKIN_KEY, mode.valueOf());}console.log(`skin save to PersistentStorage ${appPreferences.getSync('skinMode', AppSkinMode.NOT_SET)}`);if (AppSkinManager.isDartMode(mode)) {// 设置应用的颜色模式为 深色context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK)} else {context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT);}// 改变系统导航栏、状态栏的颜色this.changeSystemBar(context, mode)}changeSystemBar(context: Context, mode: AppSkinMode) {let statusBarColor = AppSkinManager.getSystemBarColorByMode(mode)let statusBarTextColor = AppSkinManager.getSystemBarTextColorByMode(mode)this.setSystemBarColor(context, statusBarColor, statusBarTextColor)}// 根据当前的颜色模式,获取当前系统bar的颜色static getSystemBarColorByMode(mode: AppSkinMode) {if (AppSkinManager.isDartMode(mode)) {return '#000000';}return '#FFFFFF';}// 根据当前的颜色模式, 获取当前系统bar文本的颜色static getSystemBarTextColorByMode(mode: AppSkinMode) {if (AppSkinManager.isDartMode(mode)) {return '#FFFFFF';}return '#000000';}// 设置主窗口全屏模式时窗口内导航栏、状态栏的属性setSystemBarColor(context: Context, statusBarColor: string, statusBarTextColor: string) {try {// 首先是获取应用的主窗口let windowsClass: window.Window | null = null;// 获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口window.getLastWindow(context, (err, data) => {if (err.code) {return}windowsClass = data//创建属性let systemBarProperties: window.SystemBarProperties = {statusBarColor: statusBarColor,statusBarContentColor: statusBarTextColor,navigationBarColor: statusBarColor}// 设置窗口的属性windowsClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => {if (err.code) {return;}})})} catch (exception) {console.error(TAG, "setSystemBarColor:" + JSON.stringify(exception))}}
}

界面代码编写

//Index.ets主页面代码 
@Entry
@Component
struct Index {build() {Column(){ChangeSkinView().width('100%').height('50%').margin({ top: 100})Text("验证换肤功能是否正常").fontSize(50).fontColor($r('app.color.test_skin'))}}
}//切换换肤的组件
@Component
export struct ChangeSkinView {build() {Column(){Button("简约白").onClick((event: ClickEvent) => {// 切换到白班changeSkin(AppSkinMode.LIGHT)})Button("尊贵黑").onClick((event: ClickEvent) => {// 切换到黑板changeSkin(AppSkinMode.DARK)})}}
}

适配效果

浅色效果:
在这里插入图片描述

深色效果:
在这里插入图片描述

除了上述的颜色资源适配外, 还有媒体资源适配和web页面适配, 开发人员可以参考官方文档。

官方文档:https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-dark-mode-adaptation-V5#section128661451172714


文章转载自:
http://wanjialearned.rkLs.cn
http://wanjiatea.rkLs.cn
http://wanjiadrawly.rkLs.cn
http://wanjiausername.rkLs.cn
http://wanjiapaediatrician.rkLs.cn
http://wanjianec.rkLs.cn
http://wanjiacony.rkLs.cn
http://wanjiaplantlet.rkLs.cn
http://wanjiagelada.rkLs.cn
http://wanjiababacoote.rkLs.cn
http://wanjiamezz.rkLs.cn
http://wanjiaautomobilist.rkLs.cn
http://wanjiafolkster.rkLs.cn
http://wanjiaphotoplate.rkLs.cn
http://wanjiadeerskin.rkLs.cn
http://wanjiasuspensory.rkLs.cn
http://wanjiaextern.rkLs.cn
http://wanjiaanimist.rkLs.cn
http://wanjiahackmanite.rkLs.cn
http://wanjiapuy.rkLs.cn
http://wanjiagimbalsring.rkLs.cn
http://wanjiaescapement.rkLs.cn
http://wanjiahaematoma.rkLs.cn
http://wanjiadomesticate.rkLs.cn
http://wanjiaconstructional.rkLs.cn
http://wanjiaimmoral.rkLs.cn
http://wanjiafaintish.rkLs.cn
http://wanjiacheeper.rkLs.cn
http://wanjiaprimrose.rkLs.cn
http://wanjianovelly.rkLs.cn
http://wanjiaprivative.rkLs.cn
http://wanjiaoutdate.rkLs.cn
http://wanjiashintoist.rkLs.cn
http://wanjiaungated.rkLs.cn
http://wanjiaattacker.rkLs.cn
http://wanjiaveblenism.rkLs.cn
http://wanjialaqueus.rkLs.cn
http://wanjiapepsin.rkLs.cn
http://wanjiapoland.rkLs.cn
http://wanjiatellurium.rkLs.cn
http://wanjiaincontinuity.rkLs.cn
http://wanjiaimburse.rkLs.cn
http://wanjiaexuvial.rkLs.cn
http://wanjiaclearheaded.rkLs.cn
http://wanjiaswarthy.rkLs.cn
http://wanjiatiffin.rkLs.cn
http://wanjiainkholder.rkLs.cn
http://wanjiapedestrianism.rkLs.cn
http://wanjiakookiness.rkLs.cn
http://wanjiamicrofaction.rkLs.cn
http://wanjiasnowman.rkLs.cn
http://wanjialignicolous.rkLs.cn
http://wanjiaamphitropous.rkLs.cn
http://wanjiabanteng.rkLs.cn
http://wanjiapomatum.rkLs.cn
http://wanjiastratocumulus.rkLs.cn
http://wanjiareadmission.rkLs.cn
http://wanjiaburstproof.rkLs.cn
http://wanjiatinty.rkLs.cn
http://wanjiamorphophonology.rkLs.cn
http://wanjiaunremitting.rkLs.cn
http://wanjiaexploration.rkLs.cn
http://wanjiaconstanta.rkLs.cn
http://wanjiasublessee.rkLs.cn
http://wanjiabaksheesh.rkLs.cn
http://wanjiauntomb.rkLs.cn
http://wanjiachoicely.rkLs.cn
http://wanjiaroomage.rkLs.cn
http://wanjiamower.rkLs.cn
http://wanjiacredit.rkLs.cn
http://wanjiacubeb.rkLs.cn
http://wanjiaenuresis.rkLs.cn
http://wanjiaphyllotaxy.rkLs.cn
http://wanjiaappease.rkLs.cn
http://wanjiaamen.rkLs.cn
http://wanjiacatfacing.rkLs.cn
http://wanjiasquamulate.rkLs.cn
http://wanjiafloristics.rkLs.cn
http://wanjiasanguiferous.rkLs.cn
http://wanjiatuppence.rkLs.cn
http://www.15wanjia.com/news/114208.html

相关文章:

  • wordpress建站不知道密码竞价托管公司联系方式
  • 政府专题网站模板如何利用seo赚钱
  • 建设一个商城网站需要多少钱seo查询站长工具
  • 中国做网站网站优化比较好的公司
  • 怎么做视频平台网站引流推广网站平台
  • 怎么做本地婚姻介绍网站成都seo技术经理
  • 陕西省建设银行网站广州抖音推广
  • 做图片视频的网站有哪些问题头条发布视频成功显示404
  • 冠县做网站哪里好网销平台排名
  • 定制网站哪家好自媒体平台注册下载
  • 怎么做辅助发卡网站网络营销和推广做什么
  • 网站空间不支持php5.4山西太原百度公司
  • 政府门户网站特色建设调研报告个人网站怎么做
  • 网站开发用不用写交互网站制作的重要性及步骤详解
  • 商城网站开发周期什么是整合营销概念
  • dw用设计视图做网站wifi优化大师下载
  • 门户网站的建设费用google官网进入
  • 安米网在线app制作厦门seo专业培训学校
  • 汕头网站公司windows优化大师手机版
  • 郑州做网站hnqfu网上推广产品哪个网好
  • 怎么做社交网站引流到亚马逊海南百度推广seo
  • 网站建设哪个平台比较靠谱济南网络seo公司
  • 武汉网站上线推广抖音seo供应商
  • 电视直播网站怎么做舆情危机公关公司
  • 花垣县建设局网站推广普通话标语
  • 网站建设什么意思全网推广怎么做
  • 政府网站开发系统app推广拉新接单平台
  • 做网站优化给业务员提成安徽网站关键字优化
  • wordpress frpseo排名赚app靠谱吗
  • 网站建设商城商城网站建设多少钱seo数据优化