Flex4之皮肤定制
Flex4之皮肤定制【Skin类和Skin类】 博客分类:
第一、关于spark.skin.SparkSkin类的
2.SparkSkin示例 在Flex SDK 4(Gumbo)中,我们只需要将这个button的样式继承与SparkSkin或者Skin,然后在其中加入一些我想要的内容即可,请看以下的代码:
- <span style="font-size: medium;"><?xml version="1.0" encoding="utf-8"?>
- <s:SparkSkin
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:fx="http://ns.adobe.com/mxml/2009">
- <s:states>
- <s:State name="up"/>
- <s:State name="over"/>
- <s:State name="down"/>
- <s:State name="disabled"/>
- </s:states>
- <fx:Metadata>[HostComponent("spark.components.Button")]</fx:Metadata>
- <s:Ellipse width="100%" height="100%">
- <s:fill>
- <s:SolidColor color="0x131313" color.over="#191919" color.down="#ffffff"/>
- </s:fill>
- <s:stroke>
- <s:SolidColorStroke color="0x0c0d0d" />
- </s:stroke>
- </s:Ellipse>
- <s:RichText id="labelElement"
- fontFamily="Myriad Pro"
- fontSize="11"
- color="0xBBBBBB"
- textAlign="center"
- horizontalCenter="0"
- verticalCenter="1"
- width="100%">
- </s:RichText>
- </s:SparkSkin></span>
<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fx="http://ns.adobe.com/mxml/2009">
<s:states>
<s:State name="up"/>
<s:State name="over"/>
<s:State name="down"/>
<s:State name="disabled"/>
</s:states>
<fx:Metadata>[HostComponent("spark.components.Button")]</fx:Metadata>
<s:Ellipse width="100%" height="100%">
<s:fill>
<s:SolidColor color="0x131313" color.over="#191919" color.down="#ffffff"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke color="0x0c0d0d" />
</s:stroke>
</s:Ellipse>
<s:RichText id="labelElement"
fontFamily="Myriad Pro"
fontSize="11"
color="0xBBBBBB"
textAlign="center"
horizontalCenter="0"
verticalCenter="1"
width="100%">
</s:RichText>
</s:SparkSkin>
我们可以用以下几个方式: (1) Button { skinClass: ClassReference("com.rianote.flex.skin.KButton"); } (2)<Button skinClass="com.rianote.flex.skin.KButton" /> (3)myButton.setStyle( "skinClass", Class( KButton ));
其中skinClass也是Flex SDK 4(Gumbo)里面新增加的一个class,其作用就是设定当前这个组件的Skin。 主程序:
- <span style="font-size: medium;"><?xml version='1.0' encoding='UTF-8'?>
- <s:Application xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:fx="http://ns.adobe.com/mxml/2009"
- height="254" width="576">
- <fx:Script>
- <![CDATA[
- import com.rianote.flex.skin.Button;
- ]]>
- </fx:Script>
- <s:Button x="54" y="56" skinClass="com.rianote.flex.skin.Button" height="32"
- width="77" label="Button"/>
- </s:Application>
- </span>
<?xml version='1.0' encoding='UTF-8'?>
<s:Application xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fx="http://ns.adobe.com/mxml/2009"
height="254" width="576">
<fx:Script>
<![CDATA[
import com.rianote.flex.skin.Button;
]]>
</fx:Script>
<s:Button x="54" y="56" skinClass="com.rianote.flex.skin.Button" height="32"
width="77" label="Button"/>
</s:Application>
(2)<fx:Metadata>[HostComponent("spark.components.Button")]</fx:Metadata> 含义: 我们要修改的是spark.components.Button的外形,Flex SDK 4(Gumbo)新增了一个matadata tag:HostComponent.同时,Metadata也由原来的mx:变成了现在的fx,因为namespace发生了改变。
(3)<s:states> <s:State name="up"/> <s:State name="over"/> <s:State name="down"/> <s:State name="disabled"/> </s:states> 含义: 定义了Button的四种状态:up、down、over、disabled。这是Flex SDK 4(Gumbo)新增的一种功能,用State来描述状态。 在Flex SDK 3的情况下,只能描述UI的不同状态,而在Flex SDK 4(Gumbo)中,又赋予了State描述控件状态的功能。
(4)<s:Ellipse width="100%" height="100%"> </s:Ellipse> 含义: 画一个圆形(椭圆形)的图形,而Ellipse也是Flex SDK 4(Gumbo)新增一个包:spark.primitives里面的一个class。 spark.primitives里面定义了一些图形,例如:Ellipse、Rect、Path、Line等class。同样根据这些class name就可以得出是做什么用的。
(5)<s:fill> <s:SolidColor color="0x131313" color.over="#191919" color.down="#ffffff"/> </s:fill> 含义: 设定填充的方式(SolidColor)填充颜色值0x131313的颜色,color.over是指鼠标移动上去后的颜色,color.down是鼠标按下时候的颜色。 引申一下,还有color.up、color.display,通过这些值就可以描述四种状态时的颜色。 另外,请注意一下,SolidColor外层必须要有<s:fill>否则会出现错误。而fill的含义是:填充。
(6)<s:stroke> <s:SolidColorStroke color="0x0c0d0d" /> </s:stroke> 含义: 设定边线的颜色(SolidColorStroke)当然也可以设定诸如:color.up、color.display、color.down、color.over的颜色。 同样SolidColorStroke必须在stroke内部,而stroke的含义:设定边框。
(7)我们在重新看一下这些代码的意义: <s:Ellipse width="100%" height="100%"> <s:fill> <s:SolidColor color="0x131313" color.over="#191919" color.down="#ffffff"/> </s:fill> <s:stroke> <s:SolidColorStroke color="0x0c0d0d" /> </s:stroke> </s:Ellipse> 含义: 定义一个圆形(因为宽和高相等)然后填充一个0x131313的颜色,并且设定鼠标移上、按下时的颜色值(color.over="#191919" color.down="#ffffff")然后在定义一个边框,设定颜色为0x0c0d0d。
(8)<s:RichText id="labelElement" fontFamily="Myriad Pro" fontSize="11" color="0xBBBBBB" textAlign="center" horizontalCenter="0" verticalCenter="1" width="100%"> </s:RichText> 含义: 上面的代码定义了Button中可以显示文字的部分。注意,id必须设定为labelElement,否则出错。其他的样式可以自行设定了。
主程序: <s:Button x="54" y="56" skinClass="com.rianote.flex.skin.Button" height="32" width="77" label="Button"/> 我们要注意的地方:skinClass,这也是Flex SDK 4(Gumbo)新增加的一个class,专门用来设定当前皮肤的properties,请注意skinClass只适用于Spark包里面的可视化控件。 以上就是这个简单的自定义Button的代码详解了,通过以上的例子,我们在Flex SDK 4(Gumbo)可以通过继承SparkSkin、Skin和skinClass的方式很简单的实现自定义组件的皮肤。
4.halo包使用定义的皮肤 看以下的代码: <fx:Style> .sparkButtonStyle { skin: ClassReference("com.rianote.flex.skin.KButton"); } </fx:Style> <mx:Button label="我是halo组件" styleName="sparkButtonStyle"/>
再让我们对比一下spark组件的写法: <fx:Style> Button { skinClass: ClassReference("com.rianote.flex.skin.KButton"); } </fx:Style> <s:Button label="我是spark组件" skinClass="com.rianote.flex.skin.KButton" />
参考文献: 1.Flex SDK 4(Gumbo)更方便的自定义样式、自定义SparkSkin .http://www.k-zone.cn/zblog/post/flash-builder-gumbo-customer-sparkskin.html
- <span style="font-size: medium;"><?xml version="1.0" encoding="utf-8"?>
- <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/halo">
- <s:layout>
- <s:BasicLayout/>
- </s:layout>
- </s:Skin></span>
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"> <s:layout>
<s:BasicLayout/>
</s:layout> </s:Skin>
- <span style="font-size: medium;"><?xml version="1.0" encoding="utf-8"?>
- <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/halo">
- <fx:Metadata>
- [HostComponent("spark.components.Button")]
- </fx:Metadata>
- <s:states>
- <mx:State name="up"/>
- <mx:State name="down"/>
- <mx:State name="over"/>
- <mx:State name="disabled"/>
- </s:states>
- <s:filters>
- <s:DropShadowFilter quality="3"
- alpha="0.5" alpha.over="0.3"
- distance="5" distance.over="15"
- blurX.over="15" blurY.over="15"
- inner.down="true"/>
- </s:filters>
- <s:Rect left="0" right="0" top="0" bottom="0" radiusX="5" radiusY="5">
- <s:fill>
- <mx:LinearGradient rotation="90">
- <mx:entries>
- <mx:GradientEntry color="#0a5c00" ratio="0.00"/>
- <mx:GradientEntry color="#84a381" ratio="0.40" ratio.over="0.25"/>
- <mx:GradientEntry color="#0a5c00" ratio="0.80"/>
- </mx:entries>
- </mx:LinearGradient>
- </s:fill>
- </s:Rect>
- <s:SimpleText id="labelDisplay" color="#ffffff"
- horizontalCenter="0" verticalCenter="0"
- left="10" right="10" top="5" bottom="5"/>
- <s:layout>
- <s:BasicLayout/>
- </s:layout>
- </s:Skin></span>
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"> <fx:Metadata>
[HostComponent("spark.components.Button")]
</fx:Metadata>
<s:states>
<mx:State name="up"/>
<mx:State name="down"/>
<mx:State name="over"/>
<mx:State name="disabled"/>
</s:states>
<s:filters>
<s:DropShadowFilter quality="3"
alpha="0.5" alpha.over="0.3"
distance="5" distance.over="15"
blurX.over="15" blurY.over="15"
inner.down="true"/>
</s:filters>
<s:Rect left="0" right="0" top="0" bottom="0" radiusX="5" radiusY="5">
<s:fill>
<mx:LinearGradient rotation="90">
<mx:entries>
<mx:GradientEntry color="#0a5c00" ratio="0.00"/>
<mx:GradientEntry color="#84a381" ratio="0.40" ratio.over="0.25"/>
<mx:GradientEntry color="#0a5c00" ratio="0.80"/>
</mx:entries>
</mx:LinearGradient>
</s:fill>
</s:Rect>
<s:SimpleText id="labelDisplay" color="#ffffff"
horizontalCenter="0" verticalCenter="0"
left="10" right="10" top="5" bottom="5"/> <s:layout>
<s:BasicLayout/>
</s:layout>
</s:Skin>
Flex4之皮肤定制的更多相关文章
- WPF,Silverlight与XAML读书笔记第四十六 - 外观效果之三皮肤与主题
说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 皮肤 皮肤是应用程序中样式与模板的集合,可以 ...
- easyui自定义皮肤及缺陷修改
引言: 一个商业项目的需要,又因为时间紧迫的关系,准备购买一套简洁,易用,可定制化强的UI,经过对国内外多家UI产品进行了对比, 包括:FineUI, EasyUI, EXT.NET, EXTJS, ...
- EUI库 - 皮肤
皮肤分离机制 皮肤分离机制对制作可复用的外观比较有优势 那对于只使用一次的皮肤呢?如果也拆分出两个文件,显然不太方便.这里我们针对单次使用的皮肤定制了内部类的功能 每个组件都有一个chi ...
- 弹层组件-layer
layer是Layui的一个弹层组建,功能强大,总之我很喜欢,下面介绍这个组件的基本用法. 首先如果只需要使用layer而不想使用Layui可以单独下载layer组件包,页面引入jquery1.8以上 ...
- 11个好用的jQuery拖拽拖放插件
这次我们整理一些拖拽播放类型的jQuery插件,这些可能不是很常用,但偶尔会有网站设计项目用到,特别是后台相关的开发项目,这个拖放排序功能一般都会有,所以适合大家收藏起来,方便日后使用.接下来一起看盾 ...
- Android 打造自己的个性化应用(一):应用程序换肤主流方式的分析与概述
Android平台api没有特意为换肤提供一套简便的机制,这可能是外国的软件更注重功能和易用,不流行换肤.系统不提供直接支持,只能自行研究. 换肤,可以认为是动态替换资源(文字.颜色.字体大小.图片. ...
- [阿当视频]WEB组件学习笔记
— 视频看完了,自定义事件还不懂,等完全懂了再更新并完成整篇案例 1. JS分层和组件的种类浏览器底层包括HTML CSS JS(DOM/BOM/Style/Canvas 2D/WebGl/SVG) ...
- 网购的一套UI代码的始末
引言: 一个商业项目的需要,又因为时间紧迫的关系,准备购买一套简洁,易用,可定制化强的UI,经过对国内外多家UI产品进行了对比, 包括:FineUI, EasyUI, EXT.NET, EXTJS, ...
- 阿里云Prismplayer-Web播放器的使用
Prismplayer是一套在线视频播放技术方案,同时支持Flash和Html5两种播放技术,可对播放器进行功能配置和皮肤定制.其在线使用文档地址为:https://help.aliyun.com/d ...
随机推荐
- linux配制DNS服务器基本能功能
1.环境 Centos 6.5 bind 关闭防火墙和SELINUX 2.安装bind服务软件 yum -y install bind 3.配制主配制文件/etc/name.conf options ...
- 轻量级集群管理软件-Ansible
ansible概述和运行机制 ansible概述 Ansible是一款为类Unix系统开发的自由开源的配置和自动化工具, 它用Python写成,类似于saltstack和Puppet,但是有一个不同 ...
- CentOS 7 配置DHCP中继代理服务
DHCP服务器只作用于局域网同一网段内,客户端是通过广播消息来获得DHCP服务器响应后才能得到IP地址的,但广播消息不能跨越子网,那么如何让客户端获取到DHCP服务器提供的IP地址呢?这就是DHCP中 ...
- STS4 add spring bean configuration file
转自:https://blog.csdn.net/asc_123456/article/details/83216577
- window.location.replace和window.location.href的区别
简单说说:有3个jsp页面(1.jsp, 2.jsp, 3.jsp). 进系统默认的是1.jsp ,当我进入2.jsp的时候, 2.jsp里面用window.location.replace(&q ...
- cxf整合spring中出现的错误
Caused by: java.lang.ClassNotFoundException: javax.wsdl.extensions.ElementExtensible at org.apache.c ...
- java消息服务学习之JMS高级特性
将介绍的内容是: 控制消息确认.为发送消息指定选项.创建临时目的地.使用JMS本地事务.异步发送消息 五个方面. 1.控制消息确认 在JMS消息得到确认之前,并不认为它已经成功使用.要成功使用消息,通 ...
- Charles 抓包工具(新猿旺学习总结)
Charles 抓包工具安装机操作 1.Charles 抓包工具是代理服务器工具,可以拦截数据,进行更改,返回数据,以实现前端后台的请求和响应数据的测试2.Charles 菜单介绍 Charles抓包 ...
- bui前端框架+yii整理
这个是做bui前端样式整合的时候记录的. 首先当然是要下载一个yii的源码,搭建起来. 第一步将bui的样式迁移到yii的样式目录中去 这里我在样式外面加了一个bui的文件夹,表示这个文件夹中存放的是 ...
- JZ2440学习笔记之第一个裸机程序(Keil-MDK)
CPU:S3C2440, ARM920T, Internal 4KB RAM, Support boot from NAND flash, 128MB for each bank. JZ2440:Me ...