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"
/>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With