The Toolbar widget (introduced in Android 5.0 Lollipop) can be thought of as a generalization of the action bar interface – it is intended to replace the action bar. The Toolbar can be used anywhere in an app layout, and it is much more customizable than an action bar.
TextureView
TextureView is a view that uses hardware-accelerated 2D rendering to enable a video or OpenGL content stream to be displayed.
Switch
Switch is a UI element that allows a user to toggle between two states, such as ON or OFF. The Switch default value is OFF.
Spinner
Spinner is a UI element that provides a quick way to select one value from a set. It is similar to a dropdown list.
AutoComplete
AutoCompleteTextView is an editable text view element that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop-down menu from which the user can choose an item to replace the content of the edit box with.
Popup Menu
PopupMenu is used for displaying popup menus that are attached to a particular view.
Pickers
Pickers are UI elements that allow the user to pick a date or a time using dialogs that are provided by Android.
Navigation Bar
The Navigation Bar provides navigation controls on devices that do not include hardware buttons for Home, Back, and Menu.
Gallery
Gallery is a layout widget that is used to display items in a horizontally scrolling list; it positions the current selection at the center of the view.
Edit Text
EditText is a UI element that is used for entering and modifying text.
CardView
CardView is a UI component that presents text and image content in views that resemble cards. CardView is implemented as a FrameLayout widget with rounded corners and a shadow. Typically, aCardView is used to present a single row item in a ListView or GridView view group.
Action Bar
ActionBar is a toolbar that displays the activity title, navigation interfaces, and other interactive items. Typically, the action bar appears at the top of an activity's window.
Calendar
The Calendar class is used for converting a specific instance in time to values such as year, month, hour, a day of the month, and the date of the next week. Calendar supports and provides options with calendar data, including the ability to read and write events, attendees, and reminders. By using the calendar provider in your application, data you add through the API will appear in the built-in calendar app that comes with Android.
Buttons
Buttons are UI elements that the user taps to perform an action.
Toolbox In Visual Studio
Toolbox In Xamarin
Let's Create a Basic App
Step-1
Create an Android app project named "SatyaprakashAndroidApp1".
Project Structure
AndroidManifest.xml
Every Android project must contain this file. The manifest lets you define the metadata of your application like Application Name, Package Name, Required Permissions, Activities etc. This is similar to the App.config or Web.Config files but differs in certain ways. In Xamarin, you can easily edit manifest information by going to the properties of the project. Please note that there are other values that are auto-generated by Xamarin from the attributes that you define in classes.
Resources
It’s a good practice to keep non-code resources like images, icons, and constants external to your code. Android expects you to store them in specific subfolders within the resources folder. Notice 6 different Drawable folders which are kept separated based on the DPI displays. These folders will include respective sized bitmaps & PNG images. Perhaps the most powerful Resource to be noted is the Layouts.
Layouts
Layout is the User Interface – Yes, that’s right! Whatever user sees is what is designed inside layout files. These are XML based and have the extension .axml. It decouples the presentation layer – much similar to XAML in Windows Phone.
Activity
Activity is the class responsible for setting the UI content for the users to interact! You can consider this as a code-behind for the Layout written in the resources. So the activity class will contain the presentation logic of your view. It is the class that is referenced by the Android system to do the user interaction. Activities are created or destroyed by the Android system. It’s important to understand the Active Life Cycle to effectively handle user data in the changing states such as Running, Paused, Backgrounded & Stopped. For the TripXpense app, I am yet to implement this feature. Here’s an example of an Activity.
All your Activity classes should derive from Activity base class. Notice the MainLauncher = true set of custom attribute – this is to set the starting screen for your app! OnCreate() is called when the activity is created. It’s always overridden to perform startup initializations such as...
- Creating Views
- Initializing variables
- Binding static data to lists
the SetContentView() >> It places your layout on the screen. Layouts can be accessed using the static variable Resources.Layout.<yourLayoutName>.
To get the reference of the button placed in the layout, use the helper method FindByViewId<T>() and pass the Id of the button you set in the resource. Once you get the handle, just add the event to the Click handler.
To navigate to another screen and pass some extra information along, use StartActivity() with an intent that contains the extra information. Extra information is nothing but the data that you want to pass between your screens.
Code Ref Main.axml
Open Main.axml in Resources >> Layout folder.