What is XML property xmlns:app?

梦想的初衷 提交于 2019-12-04 03:03:45

问题


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:


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'



来源:https://stackoverflow.com/questions/38493417/what-is-xml-property-xmlnsapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!