XML in Android
Introduction:-
1. XML stands for eXtensible Markup Language
2. Defined using custom tags (user-made tags)
3. In android, it is used to define the structure of an Activity using pre-defined layout types (or View-Group) such as Linear Layout, Relative Layout, Frame Layout, Table Layout.
Types of XML files in Android:-
1. activity_main.xml:-
You get this xml file while creating Android Project, along with its corresponding java file.
2. styles.xml:-
Present in "res/values/" folder, this file contains the current App theme and custom themes for the created Activities by the user.
3. dimens.xml:-
This xml file is used to define the dimensions of the View’s. Suppose we need a Button with 50dp(density pixel) height then we define the value 50dp in dimens.xml file and then use it in our app from this file.
From 2.3, the default Activity layout templates have a
4. AndroidManifest.xml:-
This xml 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 internet in our app then we need to define Internet permission in this file.
5. strings.xml:-
Present in "res/values" folder, this xml 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 enhance the reusability of the code.
6. colors.xml:-
Present in "res/values/" folder, this file is used to define the color codes that we used in our app. We simply define the color’s in this file and used them in our app from this file.
7. Drawable xml files:-
These are those xml files that are used to provide various graphics to the elements or views of application. When we need to create a custom UI we use drawable xml files. Suppose if we need to define a gradient color in the background of Button or any custom shape for a view then we create a Drawable xml file and set it in the background of View.
1. XML stands for eXtensible Markup Language
2. Defined using custom tags (user-made tags)
3. In android, it is used to define the structure of an Activity using pre-defined layout types (or View-Group) such as Linear Layout, Relative Layout, Frame Layout, Table Layout.
Types of XML files in Android:-
1. activity_main.xml:-
You get this xml file while creating Android Project, along with its corresponding java file.
2. styles.xml:-
Present in "res/values/" folder, this file contains the current App theme and custom themes for the created Activities by the user.
3. dimens.xml:-
This xml file is used to define the dimensions of the View’s. Suppose we need a Button with 50dp(density pixel) height then we define the value 50dp in dimens.xml file and then use it in our app from this file.
From 2.3, the default Activity layout templates have a
ConstraintLayout
as their root element with no margins applied to it. In the old templates, this used to be a RelativeLayout
with its margins set as resource values in dimens.xml
. Since these values are no longer in the default layout file, an empty dimens.xml
is not created in the project by default.4. AndroidManifest.xml:-
This xml 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 internet in our app then we need to define Internet permission in this file.
5. strings.xml:-
Present in "res/values" folder, this xml 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 enhance the reusability of the code.
6. colors.xml:-
Present in "res/values/" folder, this file is used to define the color codes that we used in our app. We simply define the color’s in this file and used them in our app from this file.
7. Drawable xml files:-
These are those xml files that are used to provide various graphics to the elements or views of application. When we need to create a custom UI we use drawable xml files. Suppose if we need to define a gradient color in the background of Button or any custom shape for a view then we create a Drawable xml file and set it in the background of View.
Comments
Post a Comment