Barak michaeli
Barak michaeli

Reputation: 113

Android namespaces in XML files

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
  1. If someone can explain what's the meaning of the namespaces(android , app , tool) in the XML files? is each word defines different library?

  2. As I know ,in XML files the URI is just a string which gives a unique definition to the namespace , so how does the android app connect the namespace to the library?

  3. Let say we gave the "android" word its default namespace , how come that in different elements we can choose different attributes? is each element(view item) has its unique attributes?

Upvotes: 3

Views: 2274

Answers (1)

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20930

app NameSpace

The app namespace is not specific to a library, but it is used for all attributes defined in your app, whether by your code or by libraries you import, effectively making a single global namespace for custom attributes - i.e., attributes not defined by the android system.

android NameSpace

the appcompat-v7 library uses custom attributes mirroring the android: namespace ones to support prior versions of android.

tools NameSpace

The tools namespace is a specially recognized namespace by the Android tools, so all the attributes you define on view elements in the tools-namespace will be automatically stripped when the application is packaged and there is no runtime overhead.

Reference to this answer.

In Short :

android:text --> what you would see while running the app.

tools:text --> what you would see just on preview window (when you need to design layout, but won't it to see on layout in app).

Upvotes: 2

Related Questions