My Hexaville
Spead the Word

Android XML Namespaces

android xml namespaces

So I wanted to write about a common XML mistake/unnecessary stuff that you can see sometimes


So there’s basically three different XML namespaces: app, android, tools

Android namespace used for all the default platform attributes

App is for attributes declared in libraries. Support library attributes use app namespace, just like attributes that you declare yourself. You can see attributes like app:srcCompat and app attributes that have same names as android ones. Ones with app namespace are attributes from support library for backwards compatibility

And tools namespace is used for attributes that are visible in Design preview only

This text will be visible only in preview and no text will be visible in your app. Those are really useful to get the sense of what your layout would look like without necessity of actually declaring hardcoded android attributes and then deleting them

Duplicated XML Namespaces

App namespace has this url And sometimes in library samples you can find them using that url, but name it differently, most likely something of library name. For example

And it makes no sense, because the name is library specific, but url in not, it covers all the attributes. So now it’s kind of illogical to use this namespace for views other than from that library, although you can. So you would create another namespace using same url

That’s why it makes sense to just call it app

Your Own Library

You can create a namespace that has only attributes from your own library/package instead of app one

But I’ve never used it


You can read more about app namespace here. Also some more explanation here and in general wiki page about XML namespaces. 

Also check those layout building tricks that will help you to improve your layout skills and will teach you how to copy any design out there from any app possible. As for learning purposes.


About the Author Ihor Klimov

Formerly an Android developer, lately picked up some Flutter. This blog is everything that I find exciting about Android and Flutter development. Stay tuned and hope to see you again!