FLEX实践—动态切换应用皮肤

     在同一个Application中动态切换主题,这里采用的是动态引用不同的CSS文件。

      具体步骤如下:

     1)创建CSS文件
      skyTheme.css

      /* CSS file */
.backgroudSkin
{
   backgroundColor: #89caec;
   fontWeight:bold;
 fontSize:12;
}
.applicationBar
{
    cornerRadius:20; 
    stype:solid;
    fillAlphas:0.42, 0.42;
}

 

     treeTheme.css

/* CSS file */
.backgroudSkin
{
   backgroundColor: #bee38a;
   fontWeight:bold;
 fontSize:12;
}
.applicationBar
{
    cornerRadius:5; 
    fillAlphas:0, 0;
}

 

   2)将每一个CSS文件右键选择"Compile CSS to SWF"

   3)创建ThemeTest.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" layout="absolute" styleName="backgroudSkin">
 <mx:Script>
   <![CDATA[
     import mx.styles.StyleManager;
     private var style:String;
    
     private function changeTheme(theme:String):void{

      //切换CSS文件
      StyleManager.loadStyleDeclarations(theme, true);
      
     }
   ]]>
 </mx:Script>
 <mx:ArrayCollection id="skinCollection">
      <mx:Object label="SkyTheme" data="theme/skyTheme.swf"/>
      <mx:Object label="TreeTheme" data="theme/treeTheme.swf"/>
    </mx:ArrayCollection>
 <mx:ApplicationControlBar x="10" y="10" width="100%" height="50" styleName="applicationBar">
  <mx:ComboBox id="skinSelector" dataProvider="{skinCollection}" prompt="Choose a theme"
  change="{changeTheme(skinSelector.selectedItem.data);}" width="124"/>
 </mx:ApplicationControlBar>
 <mx:RichTextEditor x="237.5" y="143" title="Title" width="693" height="378">
 </mx:RichTextEditor> 
</mx:Application>

应用效果:

1)切换皮肤前

 

2)skyTheme.css

 

3)treeTheme.css

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值