android - 命名空间 : how to know how and when to use them? 即 : xmlns:andorid, xmlns :app, xmlns:tools

标签 android android-layout android-xml

什么是xmlns:androidxmlns:appxmlns:tools,它们之间的基本区别是什么?什么时候应该使用它?

最佳答案

对于 androidapp 命名空间,使用 this link .

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.

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 Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.

还有 tools 命名空间的另一种用法,您可以在字符串等中看到它们,例如:

<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>

这有助于忽略错误。

此外,还有另一个有助于定义 TargetedAPI:

tools:targetApi

还有更多。

阅读: https://developer.android.com/studio/write/tool-attributes

关于android - 命名空间 : how to know how and when to use them? 即 : xmlns:andorid, xmlns :app, xmlns:tools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52686948/

相关文章:

关于 XML 布局标签属性的 Android SDK 信息

android - 转义空白 Android strings.xml

Android: Activity 主机?

android - 如何以编程方式在 Android 中启用 "Use location?"消息?

android - 如何在activity的1/3部分添加recyclerview

android - React native-fbsdk 未知问题?

android - 不能将 Holo 主题与 ActionBarActivity 子项一起使用(选择了正确的 API)

Android PagerAdapter 不调用 instantiateItem

Android软键盘仅 float 特定布局

android - 如何将动态创建的LinearLayout添加到ScrollView中?