Flex更改Alert提示框的字体大小和样式

来源:互联网 发布:阿里云计算认证考试 编辑:程序博客网 时间:2024/05/17 22:13
1、Alert字体大小更改

先创建一个css文件,这里我取名global.css,路径flex_src/css/global.css

.AlertTitle

    font-size: 12pt; 
    font-weight: normal;
    font-style: normal;

.AlertMessage
{
    font-size: 12pt;
    font-weight: normal;
    font-style: normal;
}

然后编写一个工具类,利用PopUpManager管理一个Alert实例,不再用其静态show方法了,例如:

public static function Prompt(msg:String,parent:DisplayObject):void{
   var alert:Alert = new Alert();
   alert.setStyle("messageStyleName","AlertMessage");
   alert.setStyle("titleStyleName","AlertTitle");
   alert.title = "提示";
   alert.text = msg;
   PopUpManager.addPopUp(alert,parent,true);
   PopUpManager.centerPopUp(alert);

}

public static function Confirm(msg:String,parent:DisplayObject,closeHandler:Function){
   var alert:Alert = new Alert();
   alert.setStyle("messageStyleName","AlertMessage");
   alert.setStyle("titleStyleName","AlertTitle");
   alert.title = "操作确认";
   alert.text = msg;
   alert.addEventListener(Event.CLOSE,closeHandler);
   alert.buttonFlags = Alert.OK | Alert.CANCEL;
   alert.defaultButtonFlag = Alert.OK;
   PopUpManager.addPopUp(alert,parent,true);
   PopUpManager.centerPopUp(alert);
}

最后在要使用Alert的地方引用该css,

然后就可以调用上面的静态方法Prompt和Confirm弹出提示框和确认框了,想修改字体样式?改css文件就可以了。编写工具类也可以更好的统一整个应用的提示框样式。以上方式经在我的项目中试验,效果刚刚的。

2、采用release模式编译swf文件压缩体积

fb3将release模式编译mxml的功能放到了file -> export -> flex builder -> release build 菜单下,经过测试,我的swf压缩了将近一倍。

3.最新又发现了,只要在应用中添加整个Application的样式,则整个应用默认字体都可以更改了。再回头看看上面的解决之道,觉得确实是麻烦得可以了。

Application {
    font-size:12px;
    font-style: normal;
    font-weight: normal;
}

在样式文件中这样设置就可以了。tooltip alert字体统一设置了。现在,可以直接Alert.show了


参照我的另外一篇博客的结尾,如何设置全局样式:

FLEX4 设置全局样式 的方法


http://blog.csdn.net/truelove12358/article/details/26572097



结果:
想要设置所有TitleWindow的边框颜色 只需要在项目启动时调用一次一下代码就可以了:
mx.containers.TitleWindow  要写带包名的全名。
 
 
var cssDeclaration:CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration("mx.containers.TitleWindow");
 //   cssDeclaration.setStyle("borderColor","#8878DD");
    cssDeclaration.setStyle("borderAlpha","7");



转载自:http://blog.csdn.net/jerry_bj/article/details/5650698


0 0
原创粉丝点击