According to https://developer.android.com/studio/write/tool-attributes you only add the namespace to the root element and then you can use the tools attributes. Though, the following code doesn't show me the specified sample text in the layout preview but simply @tools:sample/lorem[0].
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/date"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textSize="12sp"
tools:text="@tools:sample/date/ddmmyy"/>
<TextView
android:id="@+id/headline
android:layout_weight="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textSize="14sp"
tools:text="@tools:sample/lorem"/>
</LinearLayout>
Is there anything else I need to do to use android tools sample texts? Adding tools:text="My own text"
works fine so it's not that big of a deal but I am still curious to what's wrong. I tried the typical cleaning, restarting etc. already. I am using the latest Android Studio.
Thanks!
Hey try adding theme to your TextViews. For example:
where AppTheme.Light is defined in Theme.xml as