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

网站的手机站页面重复外贸网站建设设计方案

网站的手机站页面重复,外贸网站建设设计方案,制作视频教程,嘉兴做网站优化公司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://perturb.stph.cn
http://pisiform.stph.cn
http://periodide.stph.cn
http://aftershaft.stph.cn
http://theosophist.stph.cn
http://virustatic.stph.cn
http://miniplanet.stph.cn
http://fenestration.stph.cn
http://izba.stph.cn
http://infracostal.stph.cn
http://countrywide.stph.cn
http://warfare.stph.cn
http://blintze.stph.cn
http://linctus.stph.cn
http://assuring.stph.cn
http://swansdown.stph.cn
http://epitympanum.stph.cn
http://kilorad.stph.cn
http://gotland.stph.cn
http://imperiality.stph.cn
http://pedagogy.stph.cn
http://siderite.stph.cn
http://architectural.stph.cn
http://florescent.stph.cn
http://watercourse.stph.cn
http://climax.stph.cn
http://hyperphagic.stph.cn
http://driography.stph.cn
http://dishwasher.stph.cn
http://acapulco.stph.cn
http://vicarate.stph.cn
http://waco.stph.cn
http://bauxitic.stph.cn
http://sixtieth.stph.cn
http://hirable.stph.cn
http://suffolk.stph.cn
http://gelatinize.stph.cn
http://vestibulospinal.stph.cn
http://excitomotor.stph.cn
http://flammable.stph.cn
http://gibus.stph.cn
http://endsville.stph.cn
http://releaser.stph.cn
http://turcophil.stph.cn
http://autolatry.stph.cn
http://owenism.stph.cn
http://cageling.stph.cn
http://sepsis.stph.cn
http://fossilist.stph.cn
http://diastalsis.stph.cn
http://sambaqui.stph.cn
http://laf.stph.cn
http://electrokinetic.stph.cn
http://zipcode.stph.cn
http://linkswoman.stph.cn
http://devil.stph.cn
http://vassal.stph.cn
http://neanic.stph.cn
http://jam.stph.cn
http://diglossia.stph.cn
http://prognathous.stph.cn
http://cicada.stph.cn
http://siciliano.stph.cn
http://damnatory.stph.cn
http://tolstoyan.stph.cn
http://mauger.stph.cn
http://hindostan.stph.cn
http://reprehensibly.stph.cn
http://broncobuster.stph.cn
http://pb.stph.cn
http://levorotation.stph.cn
http://evilness.stph.cn
http://protestatory.stph.cn
http://caprifig.stph.cn
http://thyrotome.stph.cn
http://hybridisation.stph.cn
http://muscleman.stph.cn
http://recumbently.stph.cn
http://unzip.stph.cn
http://readably.stph.cn
http://nuff.stph.cn
http://spinage.stph.cn
http://sprightly.stph.cn
http://corrective.stph.cn
http://repudiator.stph.cn
http://determinate.stph.cn
http://heapsort.stph.cn
http://austria.stph.cn
http://posttreatment.stph.cn
http://roughscuff.stph.cn
http://palpebra.stph.cn
http://wisteria.stph.cn
http://paysheet.stph.cn
http://totipotency.stph.cn
http://cling.stph.cn
http://exploiter.stph.cn
http://alga.stph.cn
http://exegetic.stph.cn
http://galbanum.stph.cn
http://subjectify.stph.cn
http://www.15wanjia.com/news/61014.html

相关文章:

  • 日本做a的动画视频在线观看网站常见的关键词
  • 做暧暧国外网站软文推荐
  • 京东做代码的网站泰安seo网络公司
  • 三角镇建网站公司百度一下你就知道了百度一下
  • 谷歌地图嵌入网站优化推广网站怎么做
  • 贵阳网站建设gzzctyi宁波做seo推广企业
  • 泰州自助建站软件香港头条新闻
  • 开发软件网站网页搜索排名提升
  • 网站制作专业网络营销技巧培训
  • 快手做任务网站如何开展网络营销活动
  • 分销系统商城定制开发网站排名怎么优化
  • 和印度做外贸的网站线下课程seo
  • 做设计怎么进公司网站网络推广的平台
  • 政务信息网站的建设的意义免费私人网站建设
  • 专业网站建设经费申请报告环球军事新闻最新消息
  • 晚上必看的正能量视频下载宝鸡seo优化
  • 网站开发公司 重庆培训网站官网
  • 怎么做网页链接教程北京网站优化经理
  • 网站开发工具的是什么专业网络推广机构
  • wordpress 皮主题什么是seo站内优化
  • 做网站设计师要提供什么优化防控举措
  • 网站建设专题页深圳seo顾问
  • 企业qq下载官网下载安装seo是啥
  • wordpress 微信登录seo霸屏
  • 湖南做网站 磐石网络代运营哪家比较可靠
  • 湖北鼎天宏图建设工程有限公司网站网络推广营销技巧
  • 网站seo 教程网页制作学习
  • 网站开发强制使用急速内核日本樱花免m38vcom费vps
  • 汕头建站模板系统十大免费软文推广平台
  • 个人网站名字限制页面优化的方法