简体   繁体   中英

xmlns attributes in Android layouts

I'm well-versed in Java, but not that familiar with XML. In many of my layout/menu files, I have these lines:

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"

Somtimes I have all of them, sometimes just some combination. Could somebody give an explanation towards these three lines? Under which scenarios should we include each one? So far I have just been adding them in whenever Android Studio prompts me, but I would like to understand the use cases. Thanks!

Could somebody give an explanation towards these three lines?

Each declare a different XML namespace ( android , app , and tools , respectively).

Under which scenarios should we include each one?

If your XML file has one or more attributes prefixed with android: , you need to declare the android namespace. Many XML files will have these, from framework-defined runtime attributes.

If your XML file has one or more attributes prefixed with app: , you need to declare the app namespace. Some layout and menu resource files will have these, from library-defined attributes.

If your XML file has one or more attributes prefixed with tools: , you need to declare the tools namespace. Few resource files will have these, from attributes used to help the build tools understand what to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM