Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder for xml views that only apply to the design preview tab in Android Studio

In Android Studio, I'd love to be able to preview my view in the design tab. However, since the many get initialised not before runtime, the preview looks poorly empty. There are textviews and images that appear white because no string resource or image resource has been set yet. Setting the resources in xml is bad style and inflexible. I wish there was a way so that I can show placeholders that only apply in the Android Studio design preview tab. It should be possible to express something like

 <TextView
        android:id="@+id/mytext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        preview:text="lorem ipsum"
/>

<ImageView
        android:id="@+id/mytext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        preview:src="@drawable/ic_placeholder"
/>
like image 356
Brian Avatar asked Sep 15 '25 12:09

Brian


1 Answers

The correct prefix is tools.

<TextView
        android:id="@+id/mytext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="lorem ipsum" />

They even have samples you can use within the tools. Such as tools:text="@tools:sample/lorem"

For a full list of all the attributes supported, check out the docs. https://developer.android.com/studio/write/tool-attributes

like image 154
Advice-Dog Avatar answered Sep 18 '25 05:09

Advice-Dog