It is created to avoid naming conflicts in the xml’s.
In order to avoid naming conflicts by any other way we need to provide each element with a prefix.
to avoid repetitive usage of the prefix in each xml tag we use xmlns at the root of the xml. Hence we have the tag xmlns:android=”http://schemas.android.com/apk/res/android”
This namespace is not a URL but a URI also known as URN(universal resource name) which is rarely used in place of URI.
Due to this android will be responsible to identify the android related elements in the xml document which would be android:xxxxxxx etc. Without this namespace android:xxxxxxx will be not recognized.
This is just the XML Name Space declaration. We use this Name Space in order to specify that the attributes listed below, belongs to Android. Thus they starts with "android:"
You can actually create your own custom attributes. So to prevent the name conflicts where 2 attributes are named the same thing, but behave differently, we add the prefix "android:" to signify that these are Android attributes.
Thus, this Name Space declaration must be included in the opening tag of the root view of your XML file.
In XML, xmlns declares a Namespace. In fact, when you do:
<LinearLayout android:id>
</LinearLayout>
Instead of calling android:id, the xml will use http://schemas.android.com/apk/res/android:id to be unique. Generally this page doesn't exist (it's a URI, not a URL), but sometimes it is a URL that explains the used namespace.
The namespace has pretty much the same uses as the package name in a Java application.
A Uniform Resource Identifier (URI) is a string of characters which
identifies an Internet Resource.
The most common URI is the Uniform Resource Locator (URL) which
identifies an Internet domain address. Another, not so common type of
URI is the Universal Resource Name (URN).
xmlns:android This is start tag for define android namespace in Android. This is standerd convention define by android google developer. when you are using and layout default or custome, then must use this namespace.
To put in layman’s term :
without xmlns:android=”http://schemas.android.com/apk/res/android” android related tags wont be recognized in the xml document of our layout.
This is just the XML Name Space declaration. We use this Name Space in order to specify that the attributes listed below, belongs to Android. Thus they starts with "android:"
You can actually create your own custom attributes. So to prevent the name conflicts where 2 attributes are named the same thing, but behave differently, we add the prefix "android:" to signify that these are Android attributes.
Thus, this Name Space declaration must be included in the opening tag of the root view of your XML file.
This is form of xmlns:android ="@+/id". Now to refernce it we use for example
Another xmlns is
which is in form of xmlns:app = "@+/id" and its use is given below
In XML, xmlns declares a Namespace. In fact, when you do:
Instead of calling
android:id
, the xml will use http://schemas.android.com/apk/res/android:id to be unique. Generally this page doesn't exist (it's a URI, not a URL), but sometimes it is a URL that explains the used namespace.The namespace has pretty much the same uses as the package name in a Java application.
Here is an explanation.
In our examples we will only use URLs.
xmlns:android This is start tag for define android namespace in Android. This is standerd convention define by android google developer. when you are using and layout default or custome, then must use this namespace.
From the
<manifes>
element documentation.