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

腾讯建设网站首页免费html网站

腾讯建设网站首页,免费html网站,wordpress调用本分类热门文章,汕头网站建设托管【HarmonyOS】鸿蒙应用设置控件通用样式AttributeModifier#xff0c; Styles 前言 在鸿蒙中UI开发经常需要对控件样式进行统一的封装#xff0c;在API早前版本#xff0c;一般是通过 Styles进行样式封装复用#xff1a; Entry Component struct Index {build() {Column(…【HarmonyOS】鸿蒙应用设置控件通用样式AttributeModifier Styles 前言 在鸿蒙中UI开发经常需要对控件样式进行统一的封装在API早前版本一般是通过 Styles进行样式封装复用 Entry Component struct Index {build() {Column() {Text(开启广播).TxtStyle()}.height(100%).width(100%)}Styles TxtStyle(){.width(px2vp(300)).height(px2vp(100)).backgroundColor(Color.Blue).margin({top: px2vp(100)}).border({width: px2vp(2),color: Color.Blue,radius: px2vp(50)})} } Styles从API8开始支持目前从API Version 11开始支持另一种写法attributeModifier可根据开发者需要动态设置属性。 因为Styles的使用限制所以官方才新增了attributeModifier。 1.样式属性并不全面font相关属性无法设置 2.Styles修饰的函数只能在当前类中使用无法跨界面使用。 不过在单一页面内进行复用的简单样式也建议使用Styles进行样式复用。 AttributeModifier的使用 从API 11开始所有UI控件都可以设置attributeModifier属性 针对不同的UI控件有对应的基类Modifier足足79个 以Button为例封装按钮的样式我们需要找到ButtonAttribute实现AttributeModifier接口。 ButtonAttribute样式接口会提供五种样式回调 applyNormalAttribute 默认样式回调 applyPressedAttribute 按下样式回调 applyFocusedAttribute 获得焦点样式回调 applyDisabledAttribute 不可点击样式回调 applySelectedAttribute 被选择样式回调。 class CommonBtnModifier implements AttributeModifierButtonAttribute {applyNormalAttribute(instance: ButtonAttribute): void {instance.backgroundColor(Color.Blue)}applyPressedAttribute(instance: ButtonAttribute): void {instance.backgroundColor(Color.Red)} }一般情况下我们不需要处理这么多样式状态只需要处理默认态即可那只用继承ButtonModifier即可 import { ButtonModifier } from kit.ArkUIclass CommonBtnModifier implements AttributeModifierButtonModifier {applyNormalAttribute(instance: ButtonAttribute): void {instance.backgroundColor(Color.Blue)} }只需要实现默认态样式回调 当我们实现了样式封装类后只需要在UI调用的类创建对象赋值给控件即可实现样式的统一 import { CommonBtnModifier } from ../common/MyButtonModifier;Entry Component struct TextPage {State message: string Hello World;build() {RelativeContainer() {Button(this.message)// 如果你有多个控件都需要该样式赋值可以创建全局对象进行赋值.attributeModifier(new CommonBtnModifier())}.height(100%).width(100%)} }import { ButtonModifier } from kit.ArkUI // export 添加后才能导入到其他类使用。不加是无法引入该类。 export class CommonBtnModifier implements AttributeModifierButtonModifier {applyNormalAttribute(instance: ButtonAttribute): void {instance.backgroundColor(Color.Blue)} }DEMO示例 Index 界面UI import { CommonTextModifier } from ../common/CommonTextModifierEntry Component struct Index {txtModifier: CommonTextModifier new CommonTextModifier()onClickStart (){}build() {Column() {Text(开启广播).attributeModifier(this.txtModifier).onClick(this.onClickStart)Text(关闭广播).fontSize(px2fp(50)).onClick(this.onClickStart).attributeModifier(this.txtModifier).onClick(this.onClickStart)}.height(100%).width(100%)} }文本控件通用样式封装 import { TextModifier } from kit.ArkUI/*** 文本控件通用样式*/ export class CommonTextModifier implements AttributeModifierTextModifier {applyNormalAttribute(instance: TextModifier): void {instance.fontSize(px2fp(50)).fontColor(Color.White).width(px2vp(300)).height(px2vp(100)).backgroundColor(Color.Blue).textAlign(TextAlign.Center).margin({top: px2vp(100)}).border({width: px2vp(2),color: Color.Blue,radius: px2vp(50)})} }
http://www.hkea.cn/news/14292895/

相关文章:

  • 网站开发技术背景介绍微信公众号服务平台
  • 自己做网络主播的网站足球做网站首页格局
  • 12306网站开发费用wordpress 上传按钮
  • 注册网站怎么注销阳江房产网最新楼盘
  • 在国内做推广产品用什么网站好增加网站收录
  • 网站优化合同营销型网站规划建设的七大要素
  • 什么是网站app建设有一个wordpress站点
  • 丽水市莲都区建设局网站三站合一网站建设
  • android应用开发框架百度seo关键词优化排行
  • 装修公司 网站模板长春市宽城区建设局网站
  • 南通市城乡和住房建设局网站如何通过建立网站赚钱
  • iis怎么建网站网站建设入账时进那个会计科目
  • 什么网站免费做简历网站友情链接连接
  • 网络小说写作网站wordpress 前台评论
  • 成都企业网站建设哪家好seo网站页面优化
  • 三网合一网站建设系统 价格建设设计公司网站
  • 在家百度统计网站打不开张家港杨舍网站建设
  • 深圳网站建设方维网站模板站的模板展示怎么做的
  • 大连哪个企业想做网站江阴网站开发公司电话
  • wordpress怎么加快网站打开速度石家庄邮电职业技术学院
  • 网站怎样做权重涉密资质 网站建设
  • 西安企业网站排名优化工具怎样建设和维护网站
  • 网站一键生成wapwordpress 页面 浏览量
  • 馨雨公司网站建设策划方案开源快速网站搭建平台
  • 大连模板网站制作公司电话wordpress官方主题下载
  • 固镇县住房和城乡建设局网站wordpress不能注册
  • 嘉兴优化网站排名定制化网站建设公司
  • 网站建设费无形资产摊销动画做视频在线观看网站
  • 北京住房和建设部网站搭建网站案例
  • 厦门中科做网站总打电话来注册公司在哪个网站系统