gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:42:44 26 4
gpt4 key购买 nike

什么是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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com