Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is XML property xmlns:app?

XML is working good with:

xmlns:app="http://schemas.android.com/apk/res-auto"

but can't see max characters with

xmlns:app="http://schemas.android.com/tools"

which is completed by Android Studio auto .

Here is my XML:

<com.rengwuxian.materialedittext.MaterialEditText
    android:id="@+id/remark_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    app:met_maxCharacters="20"
    app:met_baseColor="@color/black"
    app:met_primaryColor="@color/white" />
like image 771
Pi Pi Avatar asked Jul 21 '16 01:07

Pi Pi


People also ask

What is xmlns app in android?

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.

What is xmlns attribute in XML?

The xmlns attribute specifies the xml namespace for a document. Note: The xmlns attribute is required in XHTML, invalid in HTML 4.01, and optional in HTML5.

Why do we use xmlns?

An XML namespace is a collection of names that can be used as element or attribute names in an XML document. The namespace qualifies element names uniquely on the Web in order to avoid conflicts between elements with the same name.

What is the difference between android and App?

android is usually used for attribute coming from Android SDK itself. app is often used if you are using the support library. You may also see other namespaces if you are using custom views (of your own or form a library). Thanks.


1 Answers

Xmlns stands for 'XML Namespace'

  • The part after ':' is the prefix for the Namespace
  • The part after '=' is the Namespace URI (the correct name for his part is actually "Namespace name").

(For further details see https://en.wikipedia.org/wiki/XML_namespace)

The namespace 'schemas.android.com/tools' is for specifying options to build the app by Android Studio, and are not included in the final app package

The namespace 'schemas.android.com/apk/res-auto' is used for all custom attributes - defined in libraries or in code. See this answer for details.

Note that any prefix can be used for a namespace, it is not mandatory to use 'app' for schemas.android.com/apk/res-auto. But the same prefix must be used when defining the custom attributes in the document, otherwise an error will be shown.

So, because met_maxCharacters is a custom attribute, it is shown when the 'schemas.android.com/apk/res-auto' namespace is used, and not with
'schemas.android.com/tools'

like image 169
Mohan Noone Avatar answered Oct 12 '22 00:10

Mohan Noone