Designtime Layout Attributes
suggest changeThese attributes are used when the layout is rendered in Android Studio, but have no impact on the runtime.
In general you can use any Android framework attribute, just using the tools: namespace rather than the android: namespace for layout preview. You can add both the android: namespace attribute (which is used at runtime) and the matching tools: attribute (which overrides the runtime attribute in the layout preview only).
Declare the tools namespace on the root element, as the later examples do.
For example the text attribute:
<EditText
tools:text="My Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Or the visibility attribute to unset a view for preview:
<LinearLayout
android:id="@+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:visibility="gone" />
Or the context attribute to associate the layout with an activity or fragment
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
</LinearLayout>
Or the showIn attribute to preview this layout inside another layout
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text"
tools:showIn="@layout/activity_main" />
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents