什么是“应用程序”Android的XML命名空间? [英] What is the 'app' Android XML namespace?

查看:190
本文介绍了什么是“应用程序”Android的XML命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我从一个 RES /菜单/ main.xml中应用命名空间的例子>文件

Here is an example of the app namespace that I've seen from a res/menu/main.xml file

<menu 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"
tools:context=".MainActivity" >
<item android:id="@+id/action_settings"
    android:title="@string/action_settings"
    android:orderInCategory="100"
    app:showAsAction="never" />
</menu>

什么是应用此处命名空间,它的目的是什么?它是一个标准的Andr​​oid XML命名空间?在应用命名空间中给定的属性(例如,应用:showAsAction ),可为相同的值选项在机器人命名空间相同的属性?

What is the app namespace here and what purpose does it serve? Is it a "standard" Android XML namespace? For a given attribute in the app namespace (e.g., app:showAsAction), are the same value options available as the same attribute in the android namespace?

文档安卓showAsAction = [ifRoom| 从来没有| withText| 永远| collapseActionView]

即,将在上述的例子的线意味着别的如果属性是代替

i.e., would the line in the above example mean something else if the attribute were instead:

android:showAsAction="never"

这几乎看起来像它可能是某种形式的子类化的机制,但我似乎无法找到从谷歌/ Android上的应用命名空间的任何真正的文件源。

It almost looks like it might be some sort of "subclassing" mechanism, but I can't seem to find any real documentation on the app namespace from Google/Android sources.

推荐答案

应用命名空间是不特定于库中,但它是用于定义的所有属性的应用程序,无论是你的code或库导入,有效地使自定义一个全局命名空间属性 - 即属性不是由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.

在这种情况下, appcompat-V7 库使用自定义属性镜像机器人:命名空间的人支持前Android的版本(例如:安卓showAsAction 仅在API11增加,但应用:showAsAction (被提供作您的应用程序的一部分)适用于所有的API级别的应用程序做) - 显然使用机器人:showAsAction 不会对那里的属性是没有定义的API层面的工作

In this case, the appcompat-v7 library uses custom attributes mirroring the android: namespace ones to support prior versions of android (for example: android:showAsAction was only added in API11, but app:showAsAction (being provided as part of your application) works on all API levels your app does) - obviously using the android:showAsAction wouldn't work on API levels where that attribute is not defined.

这篇关于什么是“应用程序”Android的XML命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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