Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Flex mobile development tips and tricks – Part 2: Styling your application's tabs and ActionBar

by Holly Schinsky

Holly Schinsky
  • devgirl.org

Content

  • Adding icons to the tabs
  • Styling the ActionBar
  • Styling tabs

Created

12 September 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
CSS Flash Builder Flex mobile RIA styling

Requirements

Prerequisite knowledge

Prior experience building applications—but not necessarily mobile apps—with Flex will help you make the most of this article.

User level

Intermediate

Required products

  • Flash Builder (Download trial)

Sample files

  • flex-mobile-dev-tips-tricks-pt2.zip

This is Part 2 of a multipart series of articles that cover tips and tricks for Flex mobile development. Part 1 focused on handling data when switching between views and between application executions. This part covers styling the ActionBar and tab components in your mobile application.

When you’re building a TabbedViewNavigatorApplication in Flex 4.5, you can customize your tabs or ActionBar (the title bar that contains title text and any other components or navigation content) in a couple of different ways. One approach would be to skin the tabs with your own custom assets (for example with FXG or skins). If your application does not need extensive customization, however, you may be able to use simple CSS properties. CSS styling provides a quick and easy way to make a dramatic change away from the default boring gray tabs.

I created a sample tabbed application to illustrate how this can be done. In the following examples you will see how adding some simple properties and just a few lines of CSS can change your ActionBar and mobile application tabs quickly!

Adding icons to the tabs

Consider the following code for a Flex TabbedViewNavigatorApplication with three tabs that link to their own first views:

<?xml version="1.0" encoding="utf-8"?> <s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"><s:ViewNavigator id="trends" label="Trends" width="100%" height="100%" firstView="views.TrendsView"/> <s:ViewNavigator id="attach" label="Attach" width="100%" height="100%" firstView="views.AttachView"/> <s:ViewNavigator id="call" label="Call Center" width="100%" height="100%" firstView="views.CallView"/> </s:TabbedViewNavigatorApplication>

By default, when you create a Flex mobile project the Mobile theme will be applied automatically (see Figure 1).

Figure 1. The sample application with the default Mobile theme.
Figure 1. The sample application with the default Mobile theme.

This is, of course, not very exciting. However, one way to make it more engaging is by adding icons to the tabs.

To add an icon to the tabs you can set the icon property on each of the ViewNavigator components to an icon of our choice. In the code below I’ve added three icons from the assets directory within my project root. .

<?xml version="1.0" encoding="utf-8"?> <s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <s:ViewNavigator id="trends" label="Trends" width="100%" height="100%" firstView="views.TrendsView" icon="@Embed('assets/column-chart-icon32.png')"/> <s:ViewNavigator id="attach" label="Attach" width="100%" height="100%" firstView="views.AttachView" icon="@Embed('assets/paperclip-icon32.png')"/> <s:ViewNavigator id="call" label="Call Center" width="100%" height="100%" firstView="views.CallView" icon="@Embed('assets/receptionist-icon32.png')"/> </s:TabbedViewNavigatorApplication>

With just that simple change, you can add character to your tabs (see Figure 2).

Figure 2. The sample application with icons on the tabs.
Figure 2. The sample application with icons on the tabs.

Styling the ActionBar

Icons on the tabs are a good start, but if you’re like me, you’re eager to change the gray colors used on the ActionBar component and tabs to match a theme that you have in mind. You can do that with CSS.

For the ActionBar you simply use the Spark selector for the ActionBar component and specify any supported styles or inherited styles to change.

Note: The Flex 4.5 ActionScript API documentation shows the specific style properties supported for each component, as well as inherited styles. It also shows if a style property has CSS inheritance or not. If you check out the ActionBar component in the API, you can see what can be styled.

Before you start changing styles, you may be interested in knowing what the default values are. For instance, you may want to know what the default font size and weight is, which may not be as obvious as the font color. You can take a look at the default CSS properties for the Mobile theme to better understand what you’re styling. On Mac OS, the defaults.css file can be found at: /Applications/Adobe Flash Builder 4.5/sdks/4.5/frameworks/projects/mobiletheme/defaults.css. On Windows, it can be found at: C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.5\sdks\4.5.0\frameworks\projects\mobiletheme\defaults.css.

Here are two snippets from that file on the ActionBar and its title:

ActionBar { chromeColor: #484848; defaultButtonAppearance: normal; skinClass: ClassReference("spark.skins.mobile.ActionBarSkin"); textShadowAlpha: .65; textShadowColor: #000000; paddingBottom: 1; paddingLeft: 0; paddingRight: 0; paddingTop: 1; } ... ActionBar #titleDisplay { color: #FFFFFF; fontSize: 28; fontWeight: bold; }

Notice the font color, size, and weight are set using the titleDisplay ID selector.

Since there’s not much to the ActionBar in my sample application—it just has a text title— I’m just going to customize the title. If you have buttons and other components within your ActionBar, you can customize supported styles for those as well.

The titleDisplay skin part of the ActionBar is easily styled using CSS. I simply set the following CSS properties for my sample application in an <fx:style> tag:

s|ActionBar { chromeColor: #229988; titleAlign: center; } s|ActionBar #titleDisplay { color: #CCCCCC; /* default color is white */ fontSize: 40; fontFamily: "Comic Sans MS"; }

The ActionBar now has centered white text on an aqua background in Comic Sans (see Figure 3).

Figure 3. The sample application with a styled ActionBar.
Figure 3. The sample application with a styled ActionBar.

Styling tabs

You can also use CSS to style the tabs in a tab bar. For this you’ll need to specify the tabBar skin part of the TabbedViewNavigator component in the CSS rule. Take another look at the defaults.css file for the Mobile theme, to see this skin part’s default settings:

TabbedViewNavigator #tabBar { chromeColor: #484848; color: #FFFFFF; fontSize: 20; fontWeight: normal; iconPlacement: top; interactionMode: mouse; skinClass: ClassReference("spark.skins.mobile.TabbedViewNavigatorTabBarSkin"); textShadowAlpha: .65; textShadowColor: #000000; }

Note: The tabBar defined in the TabbedViewNavigator component is actually a ButtonBar. The Spark TabBar is not yet optimized for mobile. If you go down the path of customizing skins, this is important to know since the TabbedViewNavigatorTabBarSkin actually extends ButtonBarSkin.

Once again, I can add a CSS rule to my application’s <fx:style> tag to customize the look of the component by adding my own style:

TabbedViewNavigator #tabBar { chromeColor: #229988; color: #CCCCCC; fontFamily: "Comic Sans MS"; iconPlacement:left; textDecoration:underline; }

Now the tabs are in Comic Sans with a background color that matches the ActionBar (see Figure 4). Keep in mind, I am definitely not a designer, but it should be apparent how easy it is to change the look of your application by simply adding a block of CSS.

Figure 4. The original sample application (left) and the application with styled tabs (right).
Figure 4. The original sample application (left) and the application with styled tabs (right).

Here’s the full source for the main tabbed application file. In addition to the CSS, it references the basic views in the views folder by setting the firstView property in the ViewNavigator objects to views.TrendsView, views.AttachView, and views.CallView respectively:

<?xml version="1.0" encoding="utf-8"?> <s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; s|ActionBar { chromeColor: #229988; titleAlign: center; } s|ActionBar #titleDisplay { color: #CCCCCC; fontSize: 40; fontFamily: "Comic Sans MS"; } s|TabbedViewNavigator #tabBar { chromeColor: #229988; color: #CCCCCC; fontFamily: "Comic Sans MS"; iconPlacement:left; textDecoration:underline; } </fx:Style> <s:ViewNavigator id="trends" label="Trends" width="100%" height="100%" firstView="views.TrendsView" icon="@Embed('assets/column-chart-icon32.png')"/> <s:ViewNavigator id="attach" label="Attach" width="100%" height="100%" firstView="views.AttachView" icon="@Embed('assets/paperclip-icon32.png')"/> <s:ViewNavigator id="call" label="Call Center" width="100%" height="100%" firstView="views.CallView" icon="@Embed('assets/receptionist-icon32.png')"/> </s:TabbedViewNavigatorApplication>

Note: The above example includes the styles within the MXML application for simplicity. However, it’s generally a good practice to create a separate CSS file to contain all of your styles and include a reference to that CSS file in your main application file.

You can explore the complete source code for this project by downloading and importing the sample files for this article.

Where to go from here

Now that you’ve seen how easy it is to style your Flex mobile application, here are some general guidelines to keep in mind:

  • If you are styling colors, text, alignment, icons, and so on then use CSS.
  • If you want to create a look with more graphical elements then use FXG, custom skins, and images.
  • If you need to skin for devices that have different dots-per-inch (DPI) densities then use CSS media filters or special skin classes in FXG loaded for each DPI you want to support. DPI varies between devices and operating systems. The iPhone 4 or iPad (both 320 DPI) have a different density than the Android Nexus One (240 DPI) and Motorola Xoom (160 DPI). Flex 4.5 has several built-in capabilities for supporting screen densities. Be sure to read Jason San Jose’s article Flex mobile skins – Part 2: Handling different pixel densities for more on this topic.

Note: If you’re targeting a specific device and you don’t know its DPI, choose that device in the Flash Builder Run Configurations or Debug Configurations dialog box, run the application on the device (or via the emulator), and inspect the runtimeDPI property off the root mobile application (either TabbedViewNavigatorApplication or ViewNavigatorApplication) via a trace statement or in the debugger.

Make a point to check out the other articles in Jason San Jose’s series, which begins with Flex mobile skins – Part 1: Optimized skinning basics. It provides tons of useful information on using FXG for skinning as well as creating density aware skins.

You may also want to check out Part 3 of this series, in which I cover how to control the visibility of the ActionBar and tabs.

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • From tags to riches: Going from Web 1.0 to Flex
  • DigiPri Widgets Sales Dashboard – Part 3: Understanding the dashboard application
  • DigiPri Widgets sales dashboard – Part 2: Setting up the server application
  • Flexible Rails excerpt: Refactoring to RubyAMF
  • DigiPri Widgets Sales Dashboard – Part 4: Exploring the code in Flash Builder
  • Tool-based approaches for data-centric RIA development
  • DigiPri Widgets Sales Dashboard – Part 1: Overview
  • Creating a rich buying experience with a data-driven RIA
  • Building a portable RIA with Flex and PDF
  • Designing Flex 3 skins and styles using Creative Suite 3 and Flex Builder 3

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement