Android development in the layout file will have the following content:
<linearlayoutxmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:tools= "Http://schemas.android.com/tools"
android:orientation= "Vertical"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Tools:context= ". Mainactivity "
/>
Where does the tools play a role? You can refer to document Http://tools.android.com/tech-docs/tools-attributes
A lot of tools are listed in this document, such as Tools:ignore/tools:targetapi/tools:locale, but what we're going to talk about today is what's at the back of the document Designtime Attributes , the document address is Http://tools.android.com/tips/layout-designtime-attributes
In the official documentation, there is a saying: These is attributes which was used when the layout was rendered inthe tool, but had no impact on the Runtim E. This is useful if your for examplewant to put sample data in your textfields for when you are editing the Layout,but Don ' t want those attributes to affect your running app.
These properties are used to render the layout without affecting the program running. That is, only when the layout is previewed, when the program runs it is equivalent to the property does not exist.
This explanation is very interesting, such as when we want to display a piece of text in the layout file, and the text content in the program may change dynamically, especially the parameters of the string content%1 $ s, such as content, previously must use Android:text display, and then adjust the size of the text color parameters, Then delete the Android:text property after completion. With the tools parameter, you can use Tools:text to display text in preview, eliminating the hassle of deleting it.
Currently commonly used are Tools:text, tools:visibility, TOOLS.SRC, Tools.background
Some restrictions are also listed in the official documentation, as follows:
- Currently only overriding existing attributes is supported. We may want to define some additional convenience attributes to make it simple-to-example choose which child in a View Flipper to show etc. currently only overriding attributes are supported
- Manually edit in your designtime attributes at this time
- They does not appear as a option in for example the Layout Editor property sheet.
- Editor code completion does not help you enter these attributes; The easiest-them is-to-first enter them in the Android namespace, and when-done replacing the prefix. You can only enter this section manually, and the code autofill will not complete
- Note that Designtime attributes is supported only for layout files themselves. You cannot use them anywhere else – in the menu XML files, in string resource definitions, etc. supports layout layouts only, Menu/resource/stri Ng temporarily does not support, this statement and http://tools.android.com/tech-docs/tools-attributes content conflict,tools-attributes <string name= "Show_all_apps" tools:ignore= "Missingtranslation" is available in > <resources xmlns:tools= "http://schemas.android.com/tools" tools:locale= "es" > Content
- Designtime attributes can only is used for the framework resources, not the custom attributes at this point. Applicable only to system-provided properties, custom properties no longer this Range
- See https://code.google.com/p/android/issues/detail?id=46186 for background or additional requests or Comments.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Xmlns:tools Usage