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.
MAFActionBar aBar = new MAFActionBar(this, R.menu.default_menu); root_layout .addView( aBar , 0);
<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.
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); } }
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.
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.
<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 >
<Style TargetType="ActionBar" Key="CalendarDayView" BasedOn="DefActionBar" platform="android"> <VisualStates> <VisualState Name="Pressed"> <Setter Property="Background" Value="#ff0075aa" /> <!-- background color --> </VisualState> </VisualStates> </ Style >
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 |