Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Custom renderer of Segmented controls for android

$
0
0

Hi,
I've created custom renderer for segment control in iOS and now I want to create same in android. Following is how I created in iOS.

`[assembly: ExportRenderer (typeof (SegmentedView), typeof (ExtendedSegmentControl))]
namespace XamarinFormsSample.iOS
{
public class ExtendedSegmentControl:ViewRenderer<SegmentedView,UISegmentedControl>
{
protected override void Dispose (bool disposing)
{
if (disposing) {
base.Control.ValueChanged -= new EventHandler (this.HandleControlValueChanged);

        }
        base.Dispose (disposing);
    }

    private void HandleControlValueChanged (object sender, EventArgs e)
    {
        base.Element.SelectedItem = base.Control.SelectedSegment;
    }

    protected override void OnElementChanged (ElementChangedEventArgs<SegmentedView> e)
    {
        base.OnElementChanged (e);
        if (e.OldElement == null) {   
            var native = new UISegmentedControl (new RectangleF(10,10,160,20));
            var segments = this.Element.SegmentItems.Split (';');
            for (int i = 0; i < segments.Length; i++) {
                native.InsertSegment (segments[i].ToString(), i, false);
            }
            native.SelectedSegment = 1;
            native.TintColor = UIColor.Green;
            base.SetNativeControl (native);
        }
    }
}

}`

I just want to know what should be used @UISegmentControl for android.

Thanks


Viewing all articles
Browse latest Browse all 58056

Trending Articles