The ActionBar appears at the top of your application when you use ViewNavigatorApplication or TabbedViewNavigatorApplication in your project. It’s a skin part in the ViewNavigator that updates as Views are pushed and popped. Since it’s built into the default ViewNavigatorSkin, you don’t normally create it on your own in MXML. Because it’s built in, styling the ActionBar a little less obvious. So, I’d like to show you a few easy ways to customize the look of the ActionBar through CSS.
ActionBar supports the chromeColor style introduced with Spark in Flex 4. This example changes the ActionBar chromeColor to red for the entire application:
<?xml version="1.0" encoding="utf-8"?>
@namespace s "library://ns.adobe.com/flex/spark";
By default, the ActionBar title is left aligned. To change the horizontal alignment of the title text, set the titleAlign style to left, center or right.
By default, the ActionBar uses flat-styled button skins for Buttons inside the navigationContent or actionContent of the application or view. These buttons are designed to be flush with the edges of the ActionBar.
The ActionBar has two built-in button styles that are controlled by the defaultButtonAppearance style. The second option is a beveled, iOS-styled look seen here:
Using defaultButtonAppearance=”beveled” is a shortcut for setting several different style values besides the Button skinClass values. These styles include padding, font sizes, and titleAlign.
Advanced CSS Selectors
Setting styles on the ActionBar will cause those styles to be inherited down to title, navigationGroup and actionGroup components. For this reason, the SDK has structured the ActionBar style rules in the Mobile theme to use advanced CSS selectors (see sdks/4.5.1/frameworks/projects/mobiletheme/defaults.css). This is done to isolate styles to specific components and skin parts. For example, you can see that the beveled button skins use a smaller font size than the ActionBar title.
Using advanced CSS selectors does have the drawback of being less obvious to override. Here’s an example of overriding the advanced CSS in the mobile theme to (1) use a normal and italic font for the title and (2) replace the arrow-styled back button in navigationContent with the same skin as buttons used in actionContent.
s|ActionBar.beveled s|Group#navigationGroup s|Button
/* use the rounded button instead of the arrow button */
Use these CSS examples in your mobile projects for quick and easy styling. For more control over the look and feel of the ActionBar, apply your own custom skins.
Share on Facebook