什么是XML属性xmlns:app? [英] What is XML property xmlns:app?

查看:313
本文介绍了什么是XML属性xmlns:app?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML适用于:

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

但看不到

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

由Android Studio auto完成.

which is completed by Android Studio auto .

这是我的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" />

推荐答案

Xmlns代表"XML命名空间"

Xmlns stands for 'XML Namespace'

  • ':'之后的部分是命名空间的前缀
  • "="之后的部分是命名空间URI(其部分的正确名称实际上是命名空间名称").

(有关更多详细信息,请参见 https://en.wikipedia.org/wiki/XML_namespace )

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

名称空间"schemas.android.com/tools"用于指定由Android Studio构建应用的选项,并且不包含在最终的应用包中

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

名称空间"schemas.android.com/apk/res-auto"用于所有自定义属性-在库或代码中定义.有关详细信息,请参见此答案.

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.

请注意,任何前缀都可以用于名称空间,对于schemas.android.com/apk/res-auto,并非必须使用"app".但是,在文档中定义自定义属性时必须使用相同的前缀,否则将显示错误.

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.

因此,由于met_maxCharacters是自定义属性,因此在使用'schemas.android.com/apk/res-auto'名称空间时显示,而不在
'schemas.android.com/tools'

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'

这篇关于什么是XML属性xmlns:app?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆