Flex中如何通过titleStyleName样式自定义Alert显示标题的例子

By Minidxer | January 25, 2009

接下来的例子演示了Flex中如何通过titleStyleName样式,自定义Alert显示标题。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white"
  6.         creationComplete="init();">
  7.  
  8.     <mx:Style>
  9.         @font-face {
  10.             src: local("Comic Sans MS");
  11.             fontFamily: myComicSansMS;
  12.             fontWeight: normal;
  13.         }
  14.  
  15.         Alert {
  16.             titleStyleName: myCustomTitleStyleName;
  17.         }
  18.  
  19.         .myCustomTitleStyleName {
  20.             color: haloOrange;
  21.             fontFamily: myComicSansMS;
  22.             fontSize: 16;
  23.             fontWeight: normal;
  24.         }
  25.     </mx:Style>
  26.  
  27.     <mx:Script>
  28.         <![CDATA[
  29.             import mx.controls.Alert;
  30.  
  31.             private var alert:Alert;
  32.  
  33.             private function init():void {
  34.                 var myMessage:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\nDonec tincidunt sollicitudin sem.";
  35.                 var myTitle:String = "The quick brown fox jumped over the lazy dog";
  36.                 alert = Alert.show(myMessage, myTitle);
  37.             }
  38.         ]]>
  39.     </mx:Script>
  40.  
  41.     <mx:ApplicationControlBar dock="true">
  42.         <mx:Button label="Launch alert" click="init();" />
  43.     </mx:ApplicationControlBar>
  44.  
  45. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Alert | No Comments » | 917 views Tags: ,

Search Posts