Xamarin – Android Activity Lifecycle ”; Previous Next When a user navigates through an Android App, a series of events occurs. For example, when a user launches an app, e.g., the Facebook App, it starts and becomes visible on the foreground to the user, onCreate() → onStart() → onResume(). If another activity starts, e.g., a phone call comes in, then the Facebook app will go to the background and the call comes to the foreground. We now have two processes running. onPause() — > onStop() When the phone call ends, the Facebook app returns to the foreground. Three methods are called. onRestart() — > onStart() — > onResume() There are 7 lifecycle processes in an Android activity. They include − onCreate − It is called when the activity is first created. onStart − It is called when the activity starts and becomes visible to the user. onResume − It is called when the activity starts interacting with the user. User input takes place at this stage. onPause − It is called when the activity runs in the background but has not yet been killed. onStop − It is called when the activity is no longer visible to the user. onRestart − It is called after the activity has stopped, before starting again. It is normally called when a user goes back to a previous activity that had been stopped. onDestroy − This is the final call before the activity is removed from the memory. The following illustration shows the Android Activity Lifecycle − Print Page Previous Next Advertisements ”;
Category: xamarin
Xamarin – Useful Resources
Xamarin – Useful Resources ”; Previous Next The following resources contain additional information on Xamarin. Please use them to get more in-depth knowledge on this. Useful Links on Xamarin Xamarin Wiki − Wikipedia Reference for Xamarin. Useful Books on Xamarin To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Xamarin – Gallery
Xamarin – Gallery ”; Previous Next A Gallery is a type of view that is used to show items in a horizontal scrollable list. The selected item is then shown at the center. In this example, you are going to create a gallery containing images which are scrollable horizontally. An image when clicked will display a number for the selected image. First of all, create a new project and give it a name, e.g., Gallery App Tutorial. Before you start to code, paste 7 images into the resource /drawable folder. Navigate to main.axml under resources folder and a gallery in between the linear layout tags. <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:background=”#d3d3d3″> <Gallery android:id=”@+id/gallery” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:padding=”10dp” /> </LinearLayout> Create a new class called ImageAdapter. This class is going to be used to bind the images to the gallery we created above. The first step is to add a class that contains a context cont which we use to store fields. public class ImageAdapter : BaseAdapter { Context cont; public ImageAdapter(Context ct) { cont = ct; } } Next, we count the array list which contains our image and returns its size. public override int Count { get { return imageArraylist.Length; } } In the next step, we get the position of the item. The following code shows how to do it. public override Java.Lang.Object GetItem(int position) { return null; } public override long GetItemId(int position) { return 0; } In the next step, we create an imageview for the items referenced by the adapter. public override View GetView(int position,View convertView, ViewGroup parent) { ImageView img = new ImageView(cont); img.SetImageResource(imageArraylist[position]); img.SetScaleType(ImageView.ScaleType.FitXy); img.LayoutParameters = new Gallery.LayoutParams(200, 100); return img; } In the final step, we create a reference to the images we added in the resources.drawable folder. To do this, we create an array to hold the collection of images. The following code explains how to do it. int[] imageArraylist = { Resource.Drawable.img1, Resource.Drawable.img2, Resource.Drawable.img3, Resource.Drawable.img4, Resource.Drawable.img5, Resource.Drawable.img6, }; } Next, we go to mainActivity.cs and insert the following code under the OnCreate() method. Gallery myGallery = (Gallery)FindViewById<Gallery>(Resource.Id.gallery); myGallery.Adapter = new ImageAdapter(this); myGallery.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs args) { Toast.MakeText(this, args.Position.ToString(), ToastLength.Short).Show(); } Finally, build and run your application to view the output. Print Page Previous Next Advertisements ”;
Xamarin – Android Resources
Xamarin – Android Resources ”; Previous Next When a new Android project is created, there are some files that are added to the project, by default. We call these default project files and folders as Android Resources. Take a look at the following screenshot. The default Android resources include the following − AndroidManifest.xml file − It contains information about your Android applications, e.g., the application name, permissions, etc. Resources folder − Resources can be images, layouts, strings, etc. that can be loaded via Android’s resource system. Resources/drawable folder − It stores all the images that you are going to use in your application. Resources/layout folder − It contains all the Android XML files (.axml) that Android uses to build user interfaces. The Resources/values folder − It contains XML files to declare key-value pairs for strings (and other types) throughout an application. This is how localization for multiple languages is normally set up on Android. Resources.designer.cs − This file is created automatically when the Android projected is created and it contains unique identifiers that reference the Android resources. MainActivity.cs file − This is the first activity of your Android application and from where the main application actions are launched from. Resource files can be accessed programmatically through a unique ID which is stored in the resources.designer.cs file. The ID is contained under a class called Resource. Any resource added to the project is automatically generated inside the resource class. The following code shows how to create a gridview project containing seven images − namespace HelloGridView { [System.CodeDom.Compiler.GeneratedCodeAttribute (“Xamarin.Android.Build.Tas ks”, “1.0.0.0”)] public partial class Resource { static Resource() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } public static void UpdateIdValues() {} public partial class Attribute { static Attribute() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Attribute() {} } public partial class Drawable { // aapt resource value: 0x7f020000 public const int Icon = 2130837504; // aapt resource value: 0x7f020001 public const int img1 = 2130837505; // aapt resource value: 0x7f020002 public const int img2 = 2130837506; // aapt resource value: 0x7f020003 public const int img3 = 2130837507; // aapt resource value: 0x7f020004 public const int img4 = 2130837508; // aapt resource value: 0x7f020005 public const int img5 = 2130837509; // aapt resource value: 0x7f020006 public const int img6 = 2130837510; // aapt resource value: 0x7f020007 public const int img7 = 2130837511; static Drawable() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Drawable() {} } public partial class Id { // aapt resource value: 0x7f050000 public const int gridview = 2131034112; static Id() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Id() {} } public partial class Layout { // aapt resource value: 0x7f030000 public const int Main = 2130903040; static Layout() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Layout() {} } public partial class String { // aapt resource value: 0x7f040001 public const int ApplicationName = 2130968577; // aapt resource value: 0x7f040000 public const int Hello = 2130968576; static String() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private String() {} } } } From the above code, the seven images are referenced in a class called drawable. These images are added programmatically. If a user adds another image to the project, it will also be added to the drawable class. The gridview contained in the project is also added and stored in a class on its own. Each item contained in the resources folder is automatically generated and stored in a class. Print Page Previous Next Advertisements ”;
Xamarin – Discussion
Discuss Xamarin ”; Previous Next Xamarin is a software company based in San Francisco. It provides commercial software development tools that allow a user to develop applications for Android, iOS and Windows using C# language and the .NET framework. Xamarin is built on the .NET Framework. It allows one to create apps that easily run across multiple platforms. In this tutorial, we will explain how you can use Xamarin to deliver native iOS, Android, and Windows Apps. Print Page Previous Next Advertisements ”;
Xamarin – Android Widgets
Xamarin – Android Widgets ”; Previous Next Date Picker This is a widget used to display date. In this example, we are going to create a date picker which displays the set date on a text view. First of all, create a new project and call it datePickerExample. Open Main.axml and create a datepicker, textview, and a button. <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <DatePicker android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/datePicker1” /> <TextView android:text = “Current Date” android:textAppearance = “?android:attr/textAppearanceLarge” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/txtShowDate” /> <Button android:text = “Select Date” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/btnSetDate” /> </LinearLayout> Next, go to Mainactivity.cs. We first create a private instance of a textview inside the mainActivity:Activity class. The instance will be used to store the date selected or the default date. private TextView showCurrentDate; Next, add the following code after setContentView() method. DatePicker pickDate = FindViewById<DatePicker>(Resource.Id.datePicker1); showCurrentDate = FindViewById<TextView>(Resource.Id.txtShowDate); setCurrentDate(); Button button = FindViewById<Button>(Resource.Id.btnSetDate); button.Click += delegate { showCurrentDate.Text = String.Format(“{0}/{1}/{2}”, pickDate.Month, pickDate.DayOfMonth, pickDate.Year); }; In the above code, we have referenced our datepicker, textview, and button by finding them from our main.axml file using FindViewById class. After referencing, we set the button click event which is responsible for passing the selected date from the date picker to the textview. Next, we create the setCurrentDate() method for displaying the default current date to our textview. The following code explains how it is done. private void setCurrentDate() { string TodaysDate = string.Format(“{0}”, DateTime.Now.ToString(“M/d/yyyy”).PadLeft(2, ”0”)); showCurrentDate.Text = TodaysDate; } DateTime.Now.ToString() class binds today’s time to a string object. Now, build and run the App. It should display the following output − Time Picker Time Picker is a widget used to display time as well as allowing a user to pick and set time. We are going to create a basic time picker app that displays the time and also allows a user to change the time. Go to main.axml and add a new button, textview, and a time picker as shown in the following code. <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:background = “#d3d3d3” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <TimePicker android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/timePicker1” /> <TextView android:text = “Time” android:textAppearance = “?android:attr/textAppearanceLarge” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/txt_showTime” android:textColor = “@android:color/black” /> <Button android:text = “Set Time” android:layout_width = “200dp” android:layout_height = “wrap_content” android:id = “@+id/btnSetTime” android:textColor = “@android:color/black” android:background = “@android:color/holo_green_dark” /> </LinearLayout> Go to MainActivity.cs to add the functionality for displaying a set date on the textview we created. public class MainActivity : Activity { private TextView showCurrentTime; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); TimePicker Tpicker = FindViewById<TimePicker>(Resource.Id.timePicker1); showCurrentTime = FindViewById<TextView>(Resource.Id.txt_showTime); setCurrentTime(); Button button = FindViewById<Button>(Resource.Id.btnSetTime); button.Click += delegate { showCurrentTime.Text = String.Format(“{0}:{1}”, Tpicker.CurrentHour, Tpicker.CurrentMinute); }; } private void setCurrentTime() { string time = string.Format(“{0}”, DateTime.Now.ToString(“HH:mm”).PadLeft(2, ”0”)); showCurrentTime.Text = time; } } In the above code, we first referenced the timepicker,set time button and the textview for showing time through the FindViewById<> class. We then created a click event for the set time button which on click sets the time to the time selected by a person. By default, it shows the current system time. The setCurrentTime() method class initializes the txt_showTime textview to display the current time. Now, build and run your application. It should display the following output − Spinner A spinner is a widget used to select one option from a set. It is an equivalent of a dropdown/Combo box. First of all, create a new project and call it Spinner App Tutorial. Open Main.axml under the layout folder and create a new spinner. <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <Spinner android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/spinner1” android:prompt = “@string/daysOfWeek” /> </LinearLayout> Open Strings.xml file located under values folder and add the following code to create the spinner items. <resources> <string name = “daysOfWeek”>Choose a planet</string> <string-array name = “days_array”> <item>Sunday</item> <item>Monday</item> <item>Tuesday</item> <item>Wednesday</item> <item>Thursday</item> <item>Friday</item> <item>Saturday</item> <item>Sunday</item> </string-array> </resources> Next, open MainActivity.cs to add the functionality for displaying the selected day of the week. protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the “main” layout resource SetContentView(Resource.Layout.Main); Spinner spinnerDays = FindViewById<Spinner>(Resource.Id.spinner1); spinnerDays.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(SelectedDay); var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.days_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropD ownItem); spinnerDays.Adapter = adapter; } private void SelectedDay(object sender, AdapterView.ItemSelectedEventArgs e) { Spinner spinner = (Spinner)sender; string toast = string.Format(“The selected day is {0}”, spinner.GetItemAtPosition(e.Position)); Toast.MakeText(this, toast, ToastLength.Long).Show(); } Now, build and run the application. It should display the following output − In the above code, we referenced the spinner we created in our main.axml file through the FindViewById<> class. We then created a new arrayAdapter() which we used to bind our array items from the strings.xml class. Finally we created the method SelectedDay() which we used to display the selected day of the week. Print Page Previous Next Advertisements ”;
Xamarin – Home
Xamarin Tutorial PDF Version Quick Guide Resources Job Search Discussion Xamarin is a software company based in San Francisco. It provides commercial software development tools that allow a user to develop applications for Android, iOS and Windows using C# language and the .NET framework. Xamarin is built on the .NET Framework. It allows one to create apps that easily run across multiple platforms. In this tutorial, we will explain how you can use Xamarin to deliver native iOS, Android, and Windows Apps. Audience This tutorial has been developed for beginners to help them understand the basics of creating native Apps using Xamarin. Prerequisites All the programs in this tutorial have been developed using Visual C#. Therefore, you should have a good understanding of code written in C# programming language. Print Page Previous Next Advertisements ”;
Xamarin – Quick Guide
Xamarin – Quick Guide ”; Previous Next Xamarin – Installation Xamarin is built on the .NET Framework. It allows one to create apps that easily run across multiple platforms. In this tutorial, we will explain how you can use Xamarin to deliver native iOS, Android, and Windows Apps. Let’s start the tutorial with a discussion on how to install Xamarin in Windows and Mac systems. System Requirements Windows A computer with at least 2GB of RAM and running Windows 7 or higher (Windows 8-10 is highly recommended) Visual Studio 2012 Professional or higher Xamarin for Visual Studio Mac A Mac computer running OS X Yosemite (10.10) or higher Xamarin iOS SDK Apple’s Xcode (7+) IDE and iOS SDK Xamarin Studio Installation on Windows Download the Xamarin Installer from https://www.xamarin.com/download Before running the Xamarin installer, make sure you have installed Android SDK and Java SDK on your computer. Run the downloaded installer to begin the installation process − The Xamarin license agreement screen appears. Click the Next button to accept the agreement. The installer will search for any missing components and prompt you to download and install them. After the Xamarin installation is complete, click the Close button to exit and get ready to start using Xamarin. Installation on Mac Download the Xamarin Studio Installer on your Mac system. Run the Xamarin installer you downloaded and follow the steps given in the Installation Wizard. After the installation is complete, you can start using Xamarin on your system. Xamarin – First Application In this chapter, we will see how to create a small Android application using Xamarin. Hello Xamarin! Application First of all, start a new instance of Visual Studio and go to File → New → Project. On the Menu dialog box that appears, go to Templates → Visual C# → Android → Blank App (Android). Give an appropriate name for your application. In our case, we name it “helloWorld” and save it in the default location provided. Next, click the OK button for the new “helloXamarin” project to load. On the solution, open Resources → layout → Main.axml file. Switch from Design View and go to the Source file and type the following lines of code to build your app. <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:background = “#d3d3d3” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <TextView android:text = “@string/HelloXamarin” android:textAppearance = “?android:attr/textAppearanceLarge” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/textView2” android:textColor = “@android:color/black” /> </LinearLayout> In the above code, we have created a new Android textview. Next, open the folder values and double-click Strings.xml to open it. Here, we are going to store information and values about the button created above. <?xml version = “1.0” encoding = “utf-8”?> <resources> <string name = “HelloXamarin”>Hello World, I am Xamarin!</string> <string name = “ApplicationName”>helloWorld</string> </resources> Open MainActivity.cs file and replace the existing code with the following lines of code. using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace HelloXamarin { public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); } } } Save the application. Build and then run it to display the created app in an Android Emulator. If you do not have an Android Emulator, then follow the steps given in the next section to create one. Setting Up an Android Emulator On your Visual Studio menu, go to Tools → Android → Android Emulator Manager. On the pop-up window that appears, click the Create button. It will display the following screen. On the above screen, supply the AVD name you want. Select a device that is appropriate for your display, e.g., Nexus 4” display. Select your target platform. It is always advisable to test on a minimum target platform, e.g., API 10 Android 2.3 (Gingerbread) so as to ensure your App works across all Android platforms. Fill in the rest of the fields and click the OK button. Your emulator is now ready. You can select it from the list of existing Android Virtual Devices and then click Start to launch it. Modifying HelloXamarin App In this section, we will modify our project and create a button which will display text upon click. Open main.axml and switch to source view. After our textview that we created, we will add a button as shown below. <Button android:id = “@+id/MyButton” android:layout_width = “fill_parent” android:layout_height = “wrap_content” android:text = “@string/ButtonClick” /> After adding a button, our full code will look like this − <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <TextView android:text = “@string/HelloXamarin” android:textAppearance = “?android:attr/textAppearanceLarge” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/textView2” /> <Button android:id = “@+id/MyButton” android:layout_width = “fill_parent” android:layout_height = “wrap_content” android:text = “@string/ButtonClick” /> </LinearLayout> Next, we register our button values in the strings.xml file. <string name = “ButtonClick”>Click Me!</string> After adding our button in the strings.xml file, we will open MainActivity.cs file to add an action for our button when it is clicked, as shown in the following code. using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace HelloXamarin { [Activity(Label = “HelloXamarin”, MainLauncher = true, Icon = “@drawable/icon”)] public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); Button button = FindViewById<Button>(Resource.Id.MyButton); button.Click += delegate { button.Text = “Hello world I am your first App”; }; } } } Next, build and run your application. After clicking on the button, you will get the following output − Xamarin – Application Manifest All Android Apps have a manifest file commonly referred to as AndroidManifest.xml. The manifest file contains everything about the Android platform that an App needs in order to run successfully. Here, we have listed down some of the important functions of a manifest file − It declares the minimum API level required by the application. It declares the permissions required by the application, e.g., camera, location,
Xamarin – Installation
Xamarin – Installation ”; Previous Next Xamarin is built on the .NET Framework. It allows one to create apps that easily run across multiple platforms. In this tutorial, we will explain how you can use Xamarin to deliver native iOS, Android, and Windows Apps. Let’s start the tutorial with a discussion on how to install Xamarin in Windows and Mac systems. System Requirements Windows A computer with at least 2GB of RAM and running Windows 7 or higher (Windows 8-10 is highly recommended) Visual Studio 2012 Professional or higher Xamarin for Visual Studio Mac A Mac computer running OS X Yosemite (10.10) or higher Xamarin iOS SDK Apple’s Xcode (7+) IDE and iOS SDK Xamarin Studio Installation on Windows Download the Xamarin Installer from https://www.xamarin.com/download Before running the Xamarin installer, make sure you have installed Android SDK and Java SDK on your computer. Run the downloaded installer to begin the installation process − The Xamarin license agreement screen appears. Click the Next button to accept the agreement. The installer will search for any missing components and prompt you to download and install them. After the Xamarin installation is complete, click the Close button to exit and get ready to start using Xamarin. Installation on Mac Download the Xamarin Studio Installer on your Mac system. Run the Xamarin installer you downloaded and follow the steps given in the Installation Wizard. After the installation is complete, you can start using Xamarin on your system. Print Page Previous Next Advertisements ”;
Xamarin – Building the App GUI ”; Previous Next TextView TextView is a very important component of the Android widgets. It is primarily used for displaying texts on an Android screen. To create a textview, simply open main.axml and add the following code between the linear layout tags. <TextView android:text = “Hello I am a text View” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/textview1” /> Button A button is a control used to trigger an event when it is clicked. Under your Main.axml file, type the following code to create a button. <Button android:id = “@+id/MyButton” android:layout_width = “fill_parent” android:layout_height = “wrap_content” android:text = “@string/Hello” /> Open ResourcesValuesStrings.xml and type the following line of code in between <resources> tag. <string name=”Hello”>Click Me!</string> The above code provides the value of the button we created. Next, we open MainActivity.cs and create the action to be performed when the button is clicked. Type the following code under base.OnCreate (bundle) method. Button button = FindViewById<Button>(Resource.Id.MyButton); button.Click += delegate { button.Text = “You clicked me”; }; The above code displays “You Clicked Me” when a user clicks on the button. FindViewById<< –> This method finds the ID of a view that was identified. It searches for the id in the .axml layout file. Checkbox A checkbox is used when one wants to select more than one option from a group of options. In this example, we are going to create a checkbox which on selected, displays a message that it has been checked, else it displays unchecked. To start with, we open Main.axml file in our project and type the following line of code to create a checkbox. <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:background = “#d3d3d3” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <CheckBox android:text = “CheckBox” android:padding = “25dp” android:layout_width = “300dp” android:layout_height = “wrap_content” android:id = “@+id/checkBox1” android:textColor = “@android:color/black” android:background = “@android:color/holo_blue_dark” /> </LinearLayout> Next, go to MainActivity.cs to add the functionality code. CheckBox checkMe = FindViewById<CheckBox>(Resource.Id.checkBox1); checkMe.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => { CheckBox check = (CheckBox)sender; if(check.Checked) { check.Text = “Checkbox has been checked”; } else { check.Text = “Checkbox has not been checked”; } }; From the above code, we first find the checkbox using findViewById. Next, we create a handler method for our checkbox and in our handler, we create an if else statement which displays a message depending on the outcome selected. CompoundButton.CheckedChangeEventArgs → This method fires an event when the checkbox state changes. Progress Bar A progress bar is a control that is used to show the progression of an operation. To add a progress bar, add the following line of code in Main.axml file. <ProgressBar style=”?android:attr/progressBarStyleHorizontal” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/progressBar1” /> Next, go to MainActivity.cs and set the value of the progress bar. ProgressBar pb = FindViewById<ProgressBar>(Resource.Id.progressBar1); pb.Progress = 35; In the above code, we have created a progress bar with a value of 35. Radio Buttons This is an Android widget which allows a person to choose one from a set of options. In this section, we are going to create a radio group containing a list of cars which will retrieve a checked radio button. First, we add a radio group and a textview as shown in the following code − <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:background = “@android:color/darker_gray” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <TextView android:text = “What is your favourite Car” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/textView1” android:textColor = “@android:color/black” /> <RadioGroup android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/radioGroup1” android:backgroundTint = “#a52a2aff” android:background = “@android:color/holo_green_dark”> <RadioButton android:layout_width = “wrap_content” android:layout_height = “wrap_content” android:text = “Ferrari” android:id = “@+id/radioFerrari” /> <RadioButton android:layout_width = “wrap_content” android:layout_height = “wrap_content” android:text = “Mercedes” android:id = “@+id/radioMercedes” /> <RadioButton android:layout_width = “wrap_content” android:layout_height = “wrap_content” android:text = “Lamborghini” android:id = “@+id/radioLamborghini” /> <RadioButton android:text = “Audi” android:layout_width = “match_parent” android:layout_height = “wrap_content” android:id = “@+id/radioAudi” /> </RadioGroup> </LinearLayout> To perform an action, when a radio button is clicked, we add an activity. Go to MainActivity.cs and create a new event handler as shown below. private void onClickRadioButton(object sender, EventArgs e) { RadioButton cars = (RadioButton)sender; Toast.MakeText(this, cars.Text, ToastLength.Short).Show (); } Toast.MakeText() → This is a view method used to display a message/output in a small pop up. At the bottom of the OnCreate() method just after SetContentView(), add the following piece of code. This will capture each of the radio buttons and add them to the event handler we created. RadioButton radio_Ferrari = FindViewById<RadioButton> (Resource.Id.radioFerrari); RadioButton radio_Mercedes = FindViewById<RadioButton> (Resource.Id.radioMercedes); RadioButton radio_Lambo = FindViewById<RadioButton> (Resource.Id.radioLamborghini); RadioButton radio_Audi = FindViewById<RadioButton> (Resource.Id.radioAudi); radio_Ferrari.Click += onClickRadioButton; radio_Mercedes.Click += onClickRadioButton; radio_Lambo.Click += onClickRadioButton; radio_Audi.Click += onClickRadioButton; Now, run your application. It should display the following screen as the output − Toggle Buttons Toggle button are used to alternate between two states, e.g., it can toggle between ON and OFF. Open ResourceslayoutMain.axml and add the following lines of code to create a toggle button. <?xml version = “1.0” encoding = “utf-8”?> <LinearLayout xmlns:android = “http://schemas.android.com/apk/res/android” android:orientation = “vertical” android:background = “#d3d3d3” android:layout_width = “fill_parent” android:layout_height = “fill_parent”> <ToggleButton android:id = “@+id/togglebutton” android:layout_width = “wrap_content” android:layout_height = “wrap_content” android:textOn = “Torch ON” android:textOff = “Torch OFF” android:textColor = “@android:color/black” /> </LinearLayout> We can add actions to the toggle bar when it is clicked. Open MainActivity.cs and add the following lines of code after the OnCreate() method class. ToggleButton togglebutton = FindViewById<ToggleButton> (Resource.Id.togglebutton); togglebutton.Click += (o, e) => { if (togglebutton.Checked) Toast.MakeText(this, “Torch is ON”, ToastLength.Short).Show (); else Toast.MakeText(this, “Torch is OFF”, ToastLength.Short).Show(); }; Now, when you run the App, it should display the following output − Ratings Bar A Ratings Bar is a form element that is made up of stars which app users can use to rate things you have provided for them. In your Main.axml file, create a new rating bar with 5 stars. <?xml version