Xamarin is a development platform that allows us to code native, cross-platform iOS, Android, and Windows Phone apps in C#.
UI Designers
The tools we use to create mobile user interfaces are called designers. These generate Extensible Markup Language (XML) files in their respective proprietary file formats. Two designers are available from Xamarin - "Xamarin Designer for Android" and "Xamarin Designer for iOS". With the availability of these designers, the need for the original, native XML editors has diminished. Anything you might need to build Android or iOS UIs can be found in Xamarin’s tools. However, iOS developers still frequently use the Xcode Interface Builder, and Android developers (less frequently) use XML editors, such as the Android Development Tools (ADT) plug-in for Eclipse. An XML layout is a layout provided by XML , and the tool is largely a matter of taste and personal preference, even the decision to use a designer tool at all.
Some Xamarin developers are opting to code UIs by hand in C# for all platforms with no designer used whatsoever. I recommend the designers to help learn the file formats, UI elements, and their properties. At the very least, use a designer tool like training wheels until you’re ready to ride freestyle.
Requirements
- Visual Studio RC 2017
- Xamarin Studio Packages should be installed
- Self confidence with creativity
Steps should be followed
Please follow my steps to create Dialog Fragment and use this tutorial effectively.
Step 1
Launch the Visual Studio RC 2017 and go to File >> New >> Project.
Step 2
Then, we need to select the Android template from the list, name the application, create the Project, and select where to save the project.
Step 3
Here we go. Our new project has been created successfully. Now, we need to navigate to Designer Page. To open the designer page, you need to open Solution Explorer View >> Solution Explorer.
Step 4
Then, to open "Designer" page, we need to select the following,
Solution Explorer >> Resources >> Layout >>Main.Xaml.
Step 5
Add the following code in Main.Xaml source page. This is our designer page and here, our Login System UI design will be displayed. We need to add the Message Icon in left side of our button. So, download any message icon.png from the internet and add that to drawable folder in Solution Explorer.
Go to properties of "Sign Up" Button and search for and choose the icon from "drawable" folder.
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@android:color/background_light">
- <TextView
- android:text="Create An Account"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:id="@+id/textView1"
- android:layout_weight="1"
- android:background="@android:color/darker_gray"
- android:textStyle="bold"
- android:textSize="25sp"
- android:gravity="center" />
- <Button
- android:text="Sign IN"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:id="@+id/button1"
- android:layout_weight="1"
- android:textSize="25sp"
- android:background="@android:color/holo_blue_light" />
- <TextView
- android:text="OR"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:id="@+id/textView2"
- android:layout_weight="1"
- android:background="@android:color/darker_gray"
- android:textSize="25sp"
- android:textColor="@android:color/background_light"
- android:gravity="center" />
- <Button
- android:text="Sign Up"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:id="@+id/sinup"
- android:layout_weight="1"
- android:textSize="30sp"
- android:background="@drawable/buttonsignupstyle"
- android:drawableLeft="@drawable/images" />
- <ProgressBar
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/progressBar1"
- android:layout_weight="1" />
- </LinearLayout>
Step 6
Add the following code in MainActivity.cs. This is the main activity which plays the most important role and makes your app work correctly by customizing the buttons with background activity.
MainActivity.cs
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.OS;
-
- namespace LoginSystem
- {
- [Activity(Label = "LoginSystem", MainLauncher = true, Icon = "@drawable/icon")]
- public class MainActivity : Activity
- {
-
- private Button mButtnSignup;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
-
-
- SetContentView(Resource.Layout.Main);
-
- mButtnSignup = FindViewById<Button>(Resource.Id.sinup);
- mButtnSignup.Click += (object sender, EventArgs args) =>
- {
- FragmentTransaction transcation = FragmentManager.BeginTransaction();
- Dialogclass signup = new Dialogclass();
- signup.Show(transcation, "Dialog Fragment");
- };
-
-
- }
-
-
- }
- }
Step 7
Then, we need to add the drawable objects in the "drawable" folder and create Buttonsignupstyle.xml and edittextstyle.xml files to add the following code. This gives style to our button and makes the text color.
ButtonSignup.xml
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
-
- <item android:state_pressed="false">
-
- <layer-list>
- <item android:right="5dp" android:top="5dp">
- <shape>
- <corners android:radius="2dp"/>
- <solid android:color="#D6D6D6"/>
- </shape>
- </item>
-
-
- <item android:bottom="2dp" android:left="2dp">
- <shape>
- <gradient android:angle="270" android:endColor="#F57847" android:startColor="#F57847"/>
- <stroke android:width="1dp" android:color="#BABABA"/>
- <corners android:radius="4dp"/>
- <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"/>
- </shape>
- </item>
- </layer-list>
- </item>
-
- <item android:state_pressed="true">
-
- <layer-list>
- <item android:right="5dp" android:top="5dp">
- <shape>
- <corners android:radius="2dp"/>
- <solid android:color="#D6D6D6"/>
- </shape>
- </item>
-
-
- <item android:bottom="2dp" android:left="2dp">
- <shape>
- <gradient android:angle="270" android:endColor="#E67E55" android:startColor="#F57847"/>
- <stroke android:width="1dp" android:color="#BABABA"/>
- <corners android:radius="4dp"/>
- <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"/>
- </shape>
- </item>
- </layer-list>
- </item>
-
- </selector>
edittextstyle.xml
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
-
- <item android:state_focused="true">
-
- <shape android:shape="rectangle">
-
- <gradient
- android:startColor="#FFF"
- android:endColor="#FFF">
- </gradient>
-
-
- <stroke
- android:width="3dp"
- android:color="#4A6EA9">
- </stroke>
-
- <corners
- android:radius="2dp">
- </corners>
-
- <padding
- android:left="10dp">
- </padding>
-
- </shape>
- </item>
-
- <item>
- <shape>
-
- <gradient
- android:startColor="#FFF"
- android:endColor="#FFF">
- </gradient>
-
- <corners
- android:radius="2dp">
- </corners>
-
- <padding
- android:left="10dp"
- android:top="6dp"
- android:right="10dp"
- android:bottom="6dp">
- </padding>
-
- </shape>
- </item>
-
- </selector>
Step 8
Then, we need to create the Dialog.cs file to our project. Here, it must be defined as class and add the following code in it.
Dialog.Cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
-
- namespace LoginSystem
- {
- class Dialogclass: DialogFragment
- {
- public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
- {
- base.OnCreateView(inflater, container, savedInstanceState);
- var view = inflater.Inflate(Resource.Layout.dialog_sign_up, container, false);
- return view;
-
- }
- }
- }
Final Step
Then, run the app using Visual Studio Android Emulator and here we go.
Our app gets executed.
Conclusion
If you have any doubts or queries, please comment below. In the next tutorial, I will show you how to create Sliding Tab Interface.
Thank you for reading!!!!!!!