1

What is xmlns:android, xmlns:app, xmlns:tools and what's the basic difference between them? and When I should use it?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Aamir Kalimi
  • 1,821
  • 2
  • 15
  • 19

1 Answers1

2

For android & app namespaces, use this link.

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.

In this case, the appcompat-v7 library uses custom attributes mirroring the android: namespace ones to support prior versions of android (for example: android:showAsAction was only added in API11, but app:showAsAction (being provided as part of your application) works on all API levels your app does) - obviously using the android:showAsAction wouldn't work on API levels where that attribute is not defined.

About tools;

Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.

There are also another usages of tools namespace which you can see in the strings or etc like:

<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>

Which helps to ignore errors.

Also, there is another which helps to define TargetedAPI:

tools:targetApi

And so much more.

Read: https://developer.android.com/studio/write/tool-attributes

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108