In this blog we are going to learn about how to add a Tab Bar with icons in Xamarin Android
Solution and Steps
Here are the steps to add tabs with icons in Xamarin Android app :
Steps 1 :
Create a empty xamarin android project in visual studio.
Steps 2 :
Now open your main.axml layout file which is in the Resources -> layout folder, you can choose or create your own layout file, in my case i have used main.axml file and paste the code below :
Steps 3
Now add three more file in the layout folder and name it as 'Tablayout1.axml', 'Tablayout2.axml' and 'Tablayout3.axml' and paste the code below in three tab pages :
Tablayout1.axml
Tablayout2.axml
Tablayout3.axml
Steps 4 :
Now add three icons for the three different tabs :
Steps 2 :
Now open your main.axml layout file which is in the Resources -> layout folder, you can choose or create your own layout file, in my case i have used main.axml file and paste the code below :
Steps 3
Now add three more file in the layout folder and name it as 'Tablayout1.axml', 'Tablayout2.axml' and 'Tablayout3.axml' and paste the code below in three tab pages :
Tablayout1.axml
Tablayout2.axml
Tablayout3.axml
Steps 4 :
Now add three icons for the three different tabs :
Steps 5 :
Now create a folder called "Fragments" in the main root directory of the project and add three fragment in this folder called "TabFragment1.cs", "TabFragment2.cs" and "TabFragment3.cs" and add the below code in each of the fragments cs file :
TabFragment1.cs
TabFragment2.cs
TabFragment3.cs
Steps 6 :
Now go to MainActivity.cs file and add the following code :
Here you can see the following output screen :
Now create a folder called "Fragments" in the main root directory of the project and add three fragment in this folder called "TabFragment1.cs", "TabFragment2.cs" and "TabFragment3.cs" and add the below code in each of the fragments cs file :
TabFragment1.cs
TabFragment2.cs
TabFragment3.cs
Steps 6 :
Now go to MainActivity.cs file and add the following code :
Here you can see the following output screen :