What is XML in Android?

Published by Shivam Pandey on

Basics of XML

XML stands for Extensible Markup Language. It is a markup language much like HTML but the difference is it is no predefined tags, we must define our own tags. It as itself is readable both by humans and machines. In Android, we use it for designing our layouts because it is lightweight language so it doesn’t make our layout heavy.

 

In this article, we will go through the basic concepts of XML in Android and different XML files used for a different purpose in Android. This will help you in writing a UI code to design your desired user interface.

Basics of User Interface

Android User Interface defining their whole concept using the hierarchy of view and ViewGroup objects.

Here in above diagram ViewGroup (LinearLayout) contains one view group (LinearLayout) and two views i.e, Button & TextView, Further two nested View inside main LinearLayout i.e, two EditText.

The below code snippet will explain the above concept…

Every Android application screen has some components like Button, Text images. Layouts are the best examples for ViewGroups. The different types of layout in android are LinearLayout, RelativeLayout, FrameLayout, TableLayout, AbsoluteLayout ConstraintLayout, FrameLayout.

Different XML files used in Android

1. Layout file:- Above hierarchy give basic knowledge of the layout of android.

Location of layout in Android Studio look out below picture,

2. Manifest XML File(Mainfest.xml):- This is used to define all the components of our application. It includes the names of our application packages, our Activities, receivers, services and the permissions that our application needs. For Example – Suppose we need to use the internet in our app then we need to define Internet permission in this file.

3.  Strings File(strings.xml): This file is used to replace the Hard-coded strings with a single string. We define all the strings in this XML file. And then access them in our app(Activity or in  Layout XML files) from this file. This file enhances the reusability of the code.

4. Drawable Files: These are those files that are used to provide various graphics to the elements or views of the application. When we need to create a custom UI we use drawable XML files. Suppose if we need an image, vectors we have to copy and paste to drawable file to use in our Android project.

CONNECT WITH THE AUTHOR ON LINKEDIN.

IF YOU WANT TO KNOW ABOUT ANDROID DEVELOPMENT click here.

VISIT OUR WEBSITE BRIGHTERBEES FOR MORE INFORMATION OF ANDROID DEVELOPMENT.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

STAY CONNECT WITH US