This page is obsolete. Redirecting to https://developer.android.com/studio/write/tool-attributes.html These are attributes which are used when the layout is rendered in the tool, but have no impact on the runtime. This is useful if you for example want to put sample data in your textfields for when you are editing the layout, but you don't want those attributes to affect your running app. To use designtime attributes, first make sure you have the tools namespace defined in your layout: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" ... Then, to for example set the text of a text field, use the same attribute as you would from the Android framework, but use the tools: namespace rather than the android: namespace: <TextView android:text="Name:" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText tools:text="John Doe" android:layout_width="wrap_content" android:layout_height="wrap_content" /> In the above, the Name label is using the normal text attribute, and will be shown at runtime. However, the text field is using a designtime attribute, so it will appear in the tool, but not at runtime. In general, you can set any Android framework attribute as a designtime attribute; just use the tools: namespace rather than the android: namespace. Note also that you don't have to choose either/or; you can set both the Android namespace attribute (which will be used at runtime) and a tools attribute (which will override the runtime attribute at designtime only).You can also use designtime attributes to unset an attribute while in the tools. For example, there is a bug (http://b.android.com/58448) that you cannot use the fastScrollAlwaysVisible attribute on ListViews in the layout editor. However, you may still want that attribute set at runtime. With designtime attributes you can work around it like this: <ListView android:id="@+id/listView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:fastScrollAlwaysVisible="true" tools:fastScrollAlwaysVisible=""/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First" tools:visibility="invisible" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second" tools:visibility="visible" /> (Instead of |
Tips >