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

欧美平面设计网站狼雨seo网站

欧美平面设计网站,狼雨seo网站,wordpress文章页怎么调用网站图片,磁力链Harmonyos之换肤功能 概述实现原理颜色适配颜色资源配置工具类编写界面代码编写适配效果 概述 深色模式#xff08;Dark Mode#xff09;又称之为暗色模式#xff0c;是与日常应用使用过程中的浅色模式#xff08;Light Mode#xff09;相对应的一种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://www.dnsts.com.cn/news/146909.html

相关文章:

  • 专业网站设计软件工具公司网站建设的系统功能需求分析
  • 电商网站开发平台一哈尔滨网站建设公司
  • 网站店铺vr场景可以做吗18种网络营销方式
  • 网站帮企业做推广价格怎么算物联网名词解释
  • 红酒公司的网站建设vs能建设网站吗
  • 禁忌网站wordpress 网站底部美化
  • 帮忙做公司网站莱芜金点子信息港电子版官网
  • 成都地铁建设分公司网站精品网站建设多少钱
  • 长安网站优化wordpress配置ftp服务器
  • 自建网站推广方式在线logo制作网站
  • 做网站还赚钱吗百度快速排名软件
  • 网站建设如何推广业务免费空间贴吧
  • 网站域名 评估作价公司seo营销
  • 江苏建信建设集团网站p2p网站制作流程
  • 怎么做网站域名指向外卖网站建设方案书
  • 做网站开发哪种语言更稳定高效肥乡县建设局网站
  • 网站建设费 大创seo顾问是干什么
  • 郑州的网站建设公司有哪些t恤在线定制
  • 禹城市住房和城乡建设局网站文网文许可证
  • 建筑网站大全豆丁网适合注册公司的名字大全
  • 郑州做网站好米能花型设计师服务平台
  • 免费建设网站设计页面建个网站需要多少钱一个
  • 西瓜编程网站怎么做asp.net做电商网站页面
  • 网站建设存在的具体问题论坛网站方案
  • 杭州网站建设交易wordpress 文章标题
  • 重要的龙岗网站建设百度提交网址
  • 网站建设案例欣赏网站设计学的科目
  • 烟台网站制作方案定制wordpress twig
  • 哪个网站POS机网站怎么做
  • 新能源课件网站开发新能源大连网站专业制作