MAFActionBar

The MAFActionBar control, which is compatible with Android 2.2 and later, provides the same functionalities as the native android.app.ActionBar, which is available only in Android 4.0 and later. This class implements the main action bar, which has two child action bars, a default and a contextual one. Only one action bar can be visible at any given time, and the one that appears depends on the focused view, however, only one can be visible at one time.

To create and present a default SAP style instance of MAFActionBar, use the following code. If you provide a valid menu XML resource ID, the action bar can show the overflow menu for devices without a hardware menu button.
MAFActionBar aBar = new MAFActionBar(this, R.menu.default_menu);   
root_layout .addView( aBar , 0); 
To create MAFActionBar in the Android layout XML, use:
<com.sap.maf.uicontrols.view.MAFActionBar
               android:id="@+id/dateTimeActionBar"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" /> 

MAFActionBarItem is an add-on component that represents action buttons on the right side of MAFActionBar. ActionBarItem shows a text and an icon, or only the icon, depending on the available space on the action bar.

This ActionBarItem opens another activity:
class SettingsActionBarItem extends MAFActionBarItem {

                 public SettingsActionBarItem(int id, int iconId, int textId) {
                        super(id, iconId, textId);
                 }

                 @Override
                 public void performAction() {
                        Intent prefs = new Intent(ColorApp.this, Preferences.class);
                        startActivityForResult(prefs, 100);
                 }
          } 
To add the ActionBarItem to the ActionBar, use:
SettingsActionBarItem setABI = new SettingsActionBarItem(1001, 
R.drawable.settings, R.string.action_settings);   
aBar.addDefaultAction(setABI); 

Use the contextual action bar to register to an editable component, such as editable text. The contextual action bar appears when the edit operation starts, for example, when the user taps into (??) editable text.

To register a contextual action bar, use:
private MAFActionBar aBar; 
aBar = new MAFActionBar(this, R.menu.default_menu); 
MAFEditText customText = MAFUIFactory.getInstance().getMandatoryEditText(this);  
aBar.registerForCAB(customText);   
aBar .addContextAction(customText, new DoneContextBarItem(1, R.drawable. done,
R.string. done_action )); 

The MAF skinning engine customizes the action bar. To apply SAP style, set the custom style in the XML file for background, foreground, shadow, font family, and font size.

This is the XAML content for the default style of ActionBar TargetType:
<Style TargetType="ActionBar" Key="DefActionBar" platform="android">
                 <VisualStates>
                        <VisualState Name="Pressed">
                             <Setter Property="Background" Value="#fffdb919" />
                             <!-- background color -->
                        </VisualState>
                 </VisualStates>
                 <Setter Property="Background" Value="#ff000000" />
                 <!-- background color -->
                 <Setter Property="Bg_Bottom_Shadow" Value="#ff999999" />
                 <!-- background shadow color -->
                 <Setter Property="Separator" Value="#44ffffff" />
                 <!-- background separator color -->
                 <Setter Property="Foreground" Value="#88ffffff" />
                 <!-- text color -->
                 <Setter Property="FontFamily" Value="sans_serif" />
                 <!-- font type -->
                 <Setter Property="FontSize" Value="22" />
                 <!-- font size -->
           </ Style > 
This example shows how to inherit the style definition from the standard action bar and create a flavored one:
<Style TargetType="ActionBar" Key="CalendarDayView" BasedOn="DefActionBar"
platform="android">
                 <VisualStates>
                        <VisualState Name="Pressed"> 
                              <Setter Property="Background" Value="#ff0075aa" />
                              <!-- background color -->
                        </VisualState>
                 </VisualStates>
           </ Style > 
You can change these properties in the skinning XML:
Background Color of the MAFActionBar’s background; can also be a freestyle gradient. Colors are defined as RGBA (red, green, blue, alpha).
Bg_Bottom_Shadow Background shadow color
Separator Background separator color
Foreground Text color
FontFamily Font type
FontSize Font size