Flex中如何通过buttonStyleName样式自定义Alert显示的按钮风格的例子

By Minidxer | January 25, 2009

接下来的例子演示了Flex中如何通过buttonStyleName样式,自定义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.             buttonStyleName: myCustomButtonStyleName;
  17.         }
  18.  
  19.         .myCustomButtonStyleName {
  20.             color: red;
  21.             cornerRadius: 12;
  22.             fontFamily: myComicSansMS;
  23.             fontSize: 10;
  24.             fontWeight: normal;
  25.             textDecoration: underline;
  26.             themeColor: red;
  27.         }
  28.     </mx:Style>
  29.  
  30.     <mx:Script>
  31.         <![CDATA[
  32.             import mx.controls.Alert;
  33.  
  34.             private var alert:Alert;
  35.  
  36.             private function init():void {
  37.                 var myMessage:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\nDonec tincidunt sollicitudin sem.";
  38.                 var myTitle:String = "The quick brown fox jumped over the lazy dog";
  39.                 alert = Alert.show(myMessage, myTitle);
  40.             }
  41.         ]]>
  42.     </mx:Script>
  43.  
  44.     <mx:ApplicationControlBar dock="true">
  45.         <mx:Button label="Launch alert" click="init();" />
  46.     </mx:ApplicationControlBar>
  47.  
  48. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Alert | No Comments » | 1,417 views Tags: ,

Search Posts