根据https://developer.android.com/studio/write/tool-attributes您只需将命名空间添加到根元素,然后您就可以使用工具属性。虽然,下面的代码没有在布局预览中显示指定的示例文本,而只是@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>
我还需要做什么才能使用 android 工具示例文本吗?添加tools:text="My own text"
效果很好,所以没什么大不了的,但我仍然很好奇出了什么问题。我已经尝试过典型的清洁、重新启动等。我正在使用最新的 Android Studio。谢谢!