0

如果我在未清除应用程序数据的情况下启动移动应用程序,我的皮肤类不会显示。

我在主页中有一个带有皮肤类的自定义按钮组件。皮肤类仅在我转到任何其他视图并返回主页后才会显示更改,然后我可以看到已应用的皮肤,但我无法找到在应用程序初始化时显示皮肤的方法。

主视图.mxml

<s:VGroup width="50%" height="100%" >
    <s:SkinnableContainer width="100%" height="100%" skinClass="com.abc.mobile.views.skins.BackgroundFillSkin">
        <s:VGroup width="100%" height="100%" horizontalAlign="center">
            <s:VGroup width="100%" height="50%" verticalAlign="middle" horizontalAlign="center">
                <components:ImageButton buttonMode="true" styleName="btnSrs"
                                        imageSkin="{Images.iconDashboardSR}"
                                        skinClass="com.abc.mobile.views.skins.ImageButtonSkin"
                                        id="btnSrs"/>                               
                <s:Label textAlign="center" verticalAlign="middle" styleName="homeScreenLabel" text="SRs" minWidth="120" id="lblSrs"/>
            </s:VGroup>
            <s:VGroup width="100%" height="50%" verticalAlign="middle" horizontalAlign="center">
                <components:ImageButton buttonMode="true" label="Asdsda"
                                        imageSkin="{Images.iconCR}"
                                        skinClass="com.abc.mobile.views.skins.ImageButtonSkin" id="btnCrs"/>
                <s:Label textAlign="center" verticalAlign="middle" styleName="homeScreenLabel" text="CRs" minWidth="120"/>
            </s:VGroup>             
        </s:VGroup>
    </s:SkinnableContainer>                 
</s:VGroup>

我正在使用PureMVC 框架,因此HomeViewMediator在 CREATION_COMPLETE 上调用 setupView ,它只是在其上添加了一个 MOUSECLICK 事件侦听器

homeView.btnSrs.addEventListener(MouseEvent.CLICK,showDashboard);

ImageButtonSkin.mxml皮肤类

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:mx="library://ns.adobe.com/flex/mx"
             xmlns:skins="com.abc.mobile.views.skins.*">
    <s:states>
        <s:State name="disabled"/>
        <s:State name="down"/>
        <s:State name="over"/>
        <s:State name="up"/>
    </s:states>     
    <fx:Metadata>
        [HostComponent("com.abc.mobile.views.components.ImageButton")]
    </fx:Metadata>              
    <skins:NotificationButton id="notification" 
                              visible="{int(hostComponent.toolTip)>0}"
                              includeInLayout="{int(hostComponent.toolTip)>0}"
                              depth="1" right="-10" top="-15" label="{hostComponent.toolTip}"
                              fontWeight="bold" fontSize="13" color="0x690502"/>

    <s:BitmapImage source="{hostComponent.getStyle('imageSkin')}"
                   source.up="{hostComponent.getStyle('imageSkin')}"
                   bottom="0" left="0" right="0" top="0"/>
</s:SparkSkin>

ImageButton.as

package com.abc.mobile.views.components
{
    import spark.components.Button;     
    [Style(name="imageSkin",type="*")]
    public class ImageButton extends Button
    {
        public function ImageButton()
        {
            super();
            this.buttonMode = true;
        }
    }
}

更新

在初始化时添加移动应用程序的屏幕截图并从任何其他视图返回到主页 在此处输入图像描述

更新了解决方案

override public function styleChanged(styleProp:String):void {
            super.styleChanged(styleProp);
            if (styleProp!=null) 
            {
                switch(hostComponent.id){
                    case "btnSrs": bi.source=Images.iconDashboardSR;break;
                    case "btnCrs": bi.source=Images.iconCR;break;

                }                   
                invalidateDisplayList();                    
                return;
            }
        }
4

1 回答 1

1

source="{hostComponent.getStyle('imageSkin')}"- 此绑定不会检测到样式的更改。尝试覆盖styleChanged方法以检测“imageSkin”样式更改并重新应用图像源。

于 2013-07-29T07:53:21.700 回答