Android “tools” namespace in layout xml documentation

最后都变了- 提交于 2019-11-27 19:03:47

We've just added support for designtime attributes like this in Android Studio 0.2.11. See http://tools.android.com/tips/layout-designtime-attributes for more.

Think of them as design time helpers only.They do not get processed in actual view rendering at run time.

For example you want to set background of some view in your layout design when working on android studio so that you can make clear distinction where that particular view is.So you would normally do that with

android:background="@color/<some-color>"

Now risk is that sometimes we forget to remove that color and it gets shipped in apk. instead you can do as follows:

tools:background="@color/<some-color>"

These changes will be local to android studio and will never get transferred to apk.

And also check out http://tools.android.com/tech-docs/tools-attributes for more options.

Alan1999

You will find tool attribute when you set object in graphical layout.

Listview (in graphical mode) -> right Click -> Preview List Content -> Choose Layout...

produces:

tools:listitem="@layout/customer_list_item"

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)

Namespase is

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

Design-time view attributes - The following attributes define layout characteristics that are visible only in the Android Studio layout preview.

You are able to use tools: instead of android:

For example, if the android:text attribute value is set at runtime or you want to see the layout with a value different than the default, you can add tools:text to specify some text for the layout preview only.

The tools:text attribute sets "Google Voice" as the value for the layout preview

Read more

https://developer.android.com/studio/write/tool-attributes.html#design-time_view_attributes

https://gist.github.com/lopspower/b6f80881cb290de38c75

https://android.jlelse.eu/tools-attributes-hidden-gems-of-android-studio-d7451b194e0b

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