MAFSpinner extends the capabilities of the android.widget.Spinner native spinner. MAF adds styling capabilities to the Spinner UI component, and provides predefined size variations, such as small and normal. MAF supports skinning of tapped/untapped, and enabled/disabled visual states.
LinearLayout row1 = new LinearLayout(this); MAFSpinner mss = new MAFSpinner(this); ArrayAdapter<CharSequence> a = ArrayAdapter.createFromResource(this, R.array.Days123, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mss.setAdapter(a);
<com.sap.maf.uicontrols.view.MAFSpinner android:id="@+id/MAFSpinner" android:layout_width="wrap_content" android:layout_height="50dip" android:text="skinned spinner" />
The MAF skinning engine customizes the spinners. To apply SAP style, set the custom style for background, foreground, shadow, font family, and font size in the XML file.
<Style TargetType="ComboBox" Key="SpinnerDef" platform="android"> <VisualStates> <VisualState Name="Unfocused_Enabled"> <Setter Property="Background" Value="#ff999999" /> <!-- base line color --> <Setter Property="SolidColorBrush" Value="#ff666666" /> <!-- triangle color --> <Setter Property="Foreground" Value="#ff333333" /> <!-- text color --> </VisualState>
<VisualState Name="Unfocused_Disabled"> … </VisualState> <VisualState Name="Focused_Disabled"> … </VisualState> <VisualState Name="Focused_Enabled"> … </VisualState> <VisualState Name="Pressed"> … </VisualState>
<Style TargetType="ComboBox" Key="SpinnerRed" BasedOn="SpinnerDef" platform="android"> <VisualStates> <VisualState Name="Unfocused_Enabled"> <Setter Property="Background" Value="#B60000" /> <!-- base line color --> <Setter Property="SolidColorBrush" Value="#0abb00" /> <!-- triangle color --> </VisualState> <VisualState Name="Unfocused_Disabled"> <Setter Property="Background" Value="#B60000" /> <!-- base line color --> <Setter Property="SolidColorBrush" Value="#0abb00" /> <!-- triangle color --> </VisualState> <VisualState Name="Focused_Disabled"> <Setter Property="Background" Value="#B00400" /> <!-- base line color --> <Setter Property="SolidColorBrush" Value="#0abb00" /> <!-- triangle color --> <Setter Property="BorderBrush" Value="#00F300" /> <!-- selection border color --> </VisualState> <VisualState Name="Focused_Enabled"> <Setter Property="Background" Value="#0AC200" /> <!-- base line color --> <Setter Property="SolidColorBrush" Value="#aabb00" /> <!-- triangle color --> <Setter Property="BorderBrush" Value="#FAF300" /> <!-- selection border color --> </VisualState> <VisualState Name="Pressed"> <Setter Property="Background" Value="#D00400" /> <!-- base line color --> <Setter Property="SolidColorBrush" Value="#a0bb00" /> <!-- triangle color --> <Setter Property="BorderBrush" Value="#0AF300" /> <!-- selection border color --> </VisualState> </VisualStates> </Style>
MAFSpinner mafspinner = new MAFSpinner(context,”SpinnerRed”);
Background | Color of the MAFSpinner’s background; can also be a freestyle gradient. Colors are defined as RGBA (red, green, blue, alpha). |
Foreground | Control's text color. |
SolidColorBrush | Control's triangle color. |
BorderBrush | Border attribute of the MAFSpinner. |