簡體   English   中英

Flex 4在運行時更改主應用程序的背景色

[英]Flex 4 Change Main Application Background Color at Runtime

在Flex 4中是否可以在運行時更改<s:Application>的背景顏色? 我已經看到了有關如何使用MX版本的Application組件(而不是Spark版本)執行此操作的示例。

我無法將backgroundColor屬性綁定到變量並進行修改。 但是,我認為我應該使用組件的styleManager屬性來執行此更改。

誰能解釋如何做到這一點?

感謝您的時間。

我建議您通過以下步驟:

http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fee.html

該視頻教程逐步介紹了如何使用CSS和使用Flex 4中的皮膚,這些皮膚是更改視覺組件的主要方法。

應用程序仍然具有backgroundColor樣式: http : //help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/spark/components/Application.html

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="application1_creationCompleteHandler(event)">
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                setStyle('backgroundColor',0xCCCCCC);
            }

        ]]>
    </fx:Script>
    <s:Button click="setStyle('backgroundColor','0xff0000');" label="turn red"/>
    <s:Button click="setStyle('backgroundColor','0x0000ff');" label="turn blue"/>
    <s:Button click="setStyle('backgroundColor','0x00ff00');" label="turn green"/>
</s:Application>

IMO的更好方法

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <s:layout>
        <s:HorizontalLayout/>
    </s:layout>
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
        s|Application{
            backgroundColor:#CCCCCC;
        }
    </fx:Style>
    <s:Button click="setStyle('backgroundColor','0xff0000');" label="turn red"/>
    <s:Button click="setStyle('backgroundColor','0x0000ff');" label="turn blue"/>
    <s:Button click="setStyle('backgroundColor','0x00ff00');" label="turn green"/>
</s:Application>

最好還是將CSS提取到它自己的文件中,然后使用

<fx:Style source="myStyle.css"/>

您可以嘗試

FlexGlobals.topLevelApplication.setStyle("backgroundColor", 0xff0000);  // that would turn it into bright red
FlexGlobals.topLevelApplication.setStyle("backgroundAlpha", 1);  // Sometimes background color is ignored when background alpha is zero

如果背景顏色不變,則意味着您的組件之一可能決定了背景顏色。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM