private void configureTintedSegmentedControl() { tintedSegmentedControl.setTintColor(Colors.BLUE); tintedSegmentedControl.setSelectedSegment(1); tintedSegmentedControl.addOnValueChangedListener(this); }
private void configureDefaultSegmentedControl() { defaultSegmentedControl.setMomentary(true); defaultSegmentedControl.setEnabled(false, 0); defaultSegmentedControl.addOnValueChangedListener(this); }
private void configureCustomSegmentsSegmentedControl() { Map<String, String> imageToAccessibilityLabelMappings = new HashMap<>(); imageToAccessibilityLabelMappings.put("checkmark_icon", "Done"); imageToAccessibilityLabelMappings.put("search_icon", "Search"); imageToAccessibilityLabelMappings.put("tools_icon", "Settings"); int i = 0; for (Map.Entry<String, String> entry : imageToAccessibilityLabelMappings.entrySet()) { UIImage image = UIImage.getImage(entry.getKey()); image.setAccessibilityLabel(entry.getValue()); customSegmentsSegmentedControl.setImage(image, i); i++; } customSegmentsSegmentedControl.setSelectedSegment(0); customSegmentsSegmentedControl.addOnValueChangedListener(this); }
private void configureCustomBackgroundSegmentedControl() { customBackgroundSegmentedControl.setSelectedSegment(2); // Set the background images for each control state. UIImage normalSegmentBackgroundImage = UIImage.getImage("stepper_and_segment_background"); customBackgroundSegmentedControl.setBackgroundImage( normalSegmentBackgroundImage, UIControlState.Normal, UIBarMetrics.Default); UIImage disabledSegmentBackgroundImage = UIImage.getImage("stepper_and_segment_background_disabled"); customBackgroundSegmentedControl.setBackgroundImage( disabledSegmentBackgroundImage, UIControlState.Disabled, UIBarMetrics.Default); UIImage highlightedSegmentBackgroundImage = UIImage.getImage("stepper_and_segment_background_highlighted"); customBackgroundSegmentedControl.setBackgroundImage( highlightedSegmentBackgroundImage, UIControlState.Highlighted, UIBarMetrics.Default); // Set the divider image. UIImage segmentDividerImage = UIImage.getImage("stepper_and_segment_segment_divider"); customBackgroundSegmentedControl.setDividerImage( segmentDividerImage, UIControlState.Normal, UIControlState.Normal, UIBarMetrics.Default); // Create a font to use for the attributed title (both normal and // highlighted states). UIFontDescriptor captionFontDescriptor = UIFontDescriptor.getPreferredFontDescriptor(UIFontTextStyle.Caption1); UIFont font = UIFont.getFont(captionFontDescriptor, 0); NSAttributedStringAttributes normalTextAttributes = new NSAttributedStringAttributes().setForegroundColor(Colors.PURPLE).setFont(font); customBackgroundSegmentedControl.setTitleTextAttributes( normalTextAttributes, UIControlState.Normal); NSAttributedStringAttributes highlightedTextAttributes = new NSAttributedStringAttributes().setForegroundColor(Colors.GREEN).setFont(font); customBackgroundSegmentedControl.setTitleTextAttributes( highlightedTextAttributes, UIControlState.Highlighted); customBackgroundSegmentedControl.addOnValueChangedListener(this); }