Category / Section
How to create segmented control in Xamarin.Android using axml code
1 min read
This article explains how to create a segmented control by defining in AXML in Xamarin.Android as shown the following code snippet.
[AXML]
Create axml file at Resources -> Layout. Here named content_main.axml
.. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="@dimen/abc_action_bar_content_inset_material" android:layout_width="match_parent" android:layout_height="match_parent"> <Syncfusion.Android.Buttons.SfSegmentedControl android:id = "@+id/sfSegmentedControl1" android:layout_height="48dp" android:layout_width="match_parent" /> </LinearLayout>
With the reference id of segmented control, we can populate the collection and customize their appearance as follows in MainActivity file.
[C#]
… protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.content_main); SfSegmentedControl segmentedControl = FindViewById<SfSegmentedControl>(Resource.Id.sfSegmentedControl1); List<string> list = new List<string> { "1","2","3","4","5","6" }; segmentedControl.SegmentHeight = 43; segmentedControl.ItemsSource = list; } ..
Output
See Also
How to customize the selected segment in Xamarin.Android
Scrolling in segmented control programmatically
How to populate the custom views in Xamarin.Android