What is XML property xmlns:app?

2020-04-03 05:34发布

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" />

1条回答
Melony?
2楼-- · 2020-04-03 06:21

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'

查看更多
登录 后发表回答