gpt4 book ai didi

android - 如何在 TextView 中设置默认文本以在绑定(bind)时在布局预览中看到它?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:07 27 4
gpt4 key购买 nike

所以我希望看到我的布局预览,其中的字段填充了默认占位符之类的东西,但是如果我使用绑定(bind),settext 属性已经被使用并且字段显示为空,因为还没有来自模型的信息。

<TextView
android:id="@+id/tv_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:gravity="center"
**android:text="@{showBlueportSpotViewModel.name}"**
android:textAllCaps="true"
android:textSize="20sp"
android:textStyle="bold"/>

我试过这个:

android:text="@{showBlueportSpotViewModel.name ?? @string/blueport_placeholder_name}"

但我仍然看到 View 是空的。

你们有什么解决方法吗?我想一旦找到解决方法,它就可以用于 ImageView 和 src 等。

谢谢!

最佳答案

您可以使用 tools 属性来定义将出现在布局预览中但不会在您运行应用程序时出现的属性。

将以下内容添加到您的 Root View :

xmlns:tools="http://schemas.android.com/tools"

然后使用 tools 属性定义只会出现在布局预览中的文本:

tools:text="placeholder text"

在编辑器中模拟 View 时,tools 属性非常有用。打包应用程序时,所有工具属性都将被剥离。更多信息:http://tools.android.com/tech-docs/tools-attributes

关于android - 如何在 TextView 中设置默认文本以在绑定(bind)时在布局预览中看到它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31297414/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com