Android Studio Android工具的示例文本未显示在布局预览中

yfwxisqw  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(182)

根据https://developer.android.com/studio/write/tool-attributes,您只需要将命名空间添加到根元素中,然后就可以使用tools属性了。不过,下面的代码并没有在布局预览中显示指定的示例文本,而是简单地显示了 @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。谢谢!

cgvd09ve

cgvd09ve1#

嘿,试着给你的文本视图添加主题。例如:

android:theme="@style/AppTheme.Light"

其中AppTheme.Light在Theme.xml中定义为

<style name="AppTheme.Light" parent="BaseAppTheme.Light" />

相关问题