惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
月光博客
月光博客
Jina AI
Jina AI
F
Fortinet All Blogs
博客园 - 聂微东
The Cloudflare Blog
美团技术团队
B
Blog RSS Feed
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
V
V2EX

博客园 - spoony

Flex4 Skinning 4: 留言板示例 Flex4 Skinning 2: 皮肤协议 Air应用程序访问本地数据库 [通篇转载]调程序的小女孩 Adobe ColdFusion Reports(5) Adobe ColdFusion Reports(4) Adobe ColdFusion Reports(3) Adobe ColdFusion Reports(2) Adobe ColdFusion Reports(1) Adobe ColdFusion Charts(3) Adobe ColdFusion Charts(2) Adobe ColdFusion Charts(1) Adobe ColdFusion读写Microsoft Office Excel数据(3) Adobe ColdFusion读写Microsoft Office Excel数据(2) Adobe ColdFusion读写Microsoft Office Excel数据(1) Flex与DotNET WebService交互(2) Flex与DotNET WebService交互(1) Ext JS Designer 1.0.5 发布 设置Flex Builder中FlashPlayer调试版本 - spoony - 博客园
Flex4 Skinning 1: 自定义一个简单按钮的皮肤
spoony · 2010-11-01 · via 博客园 - spoony

  Flex4使得改变应用程序的外观变得异常简单,这主要归功于新的皮肤框架(skinning architecture),通过它我们可以将组件中的可视化元素和逻辑完全分离。也正因为这个思想的引导,我们可以发现Flex4中的组件本身都不再包含外观信息的定义,而是把这些信息放在相关的皮肤(skin)文件中。

  通过这系列文章,笔者将展示一下Flex4中的皮肤框架(skinning architecture)。首先,我们为常用的按钮(Button)组件定义一个新的皮肤。

  新建相关的项目和包,然后新建一个MXML Skin文件。

Figure 1. 新建皮肤文件并将其Host component设置为apark.components.Button

  代码如下。

<?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/mx">
	<!-- host component -->
	<fx:Metadata>
		[HostComponent("spark.components.Button")]
	</fx:Metadata>
	
	<!-- states -->
	<s:states>
		<s:State name="disabled" />
		<s:State name="down" />
		<s:State name="over" />
		<s:State name="up" />
	</s:states>
	
	<!-- dropshadow for the down state only -->
	<s:Rect radiusX="4" radiusY="4" top="0" right="0" bottom="0" left="0" includeIn="down">
		<s:fill>
			<s:SolidColor color="0" />
		</s:fill>
		<s:filters>
			<s:DropShadowFilter knockout="true" blurX="5" blurY="5" alpha="0.32" distance="2" /> 
		</s:filters>
	</s:Rect>
	
	<!-- border and fill -->
	<s:Rect id="rect" radiusX="4" radiusY="4" top="0" right="0" bottom="0" left="0">
		<s:fill>
			<s:SolidColor color="0x77CC22" color.over="0x92D64E" color.down="0x67A41D" />
		</s:fill>
		<s:stroke>
			<s:SolidColorStroke color="0x131313" weight="2" />
		</s:stroke>
	</s:Rect>
	
	<!-- highlight on top -->
	<s:Rect radiusX="4" radiusY="4" top="2" right="2" left="2" height="50%">
		<s:fill>
			<s:LinearGradient rotation="90">
				<s:GradientEntry color="0xFFFFFF" alpha=".5"/>
				<s:GradientEntry color="0xFFFFFF" alpha=".1"/> 
			</s:LinearGradient>
		</s:fill>
	</s:Rect> 
	
	<!-- text -->
	<s:Label text="Simple Button" color="0x131313" 
			 textAlign="center" verticalAlign="middle" 
			 horizontalCenter="0" verticalCenter="1" 
			 left="12" right="12" top="6" bottom="6" />
		
	<!-- SkinParts
	name=labelDisplay, type=spark.components.supportClasses.TextBase, required=false
	-->
</s:Skin>

  在主应用程序文件中使用按钮并设置它的皮肤属性(skinClass)。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   minWidth="955" minHeight="600">

	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	<s:layout>
		<s:VerticalLayout />
	</s:layout>
	
	<s:Button skinClass="com.guyue.skins.SimpleButtonSkin" />
	
	<s:Button label="I am a button without customerized skin. " />
	
</s:Application>

Figure 2.

  这样一个最简单的按钮自定义皮肤就制作完成。从图2可以看出应用了我们定义的皮肤的按钮与默认的按钮的区别。使用皮肤的方法是设置组件的skinClass属性。