Android Studio设计时数据绑定回退/默认值 [英] Android Studio Design Time Data Binding Fallback/Default value

查看:77
本文介绍了Android Studio设计时数据绑定回退/默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用效果很好的Android数据绑定:

I am using Android data binding which works great:

<TextView
android:text="@{ee.Name}"
...

但是,如果我这样做,Android Studio设计器将不会显示任何文本.没有文本,我根本看不到TextView.这是可以理解的,因为我还没有绑定数据.是否有诸如备用值或默认值之类的东西可以显示,直到有真实数据为止?

But if I do that the Android Studio designer doesn't show any text. Without text I can't see the TextView at all. Which is understandable because I haven't bound the data yet. Is there something like a fallback value or a default value which can be displayed until there is real data?

推荐答案

您应该阅读 Android Studio对数据绑定的支持解释如何使用占位符,以在设计阶段为您提供帮助.很简单:

You should read the Data Binding Guide posted on the Android developers website. The last section of the document, Android Studio Support for Data Binding explain how you can use a placeholder that can help you during the design phase. It's very simple:

<TextView android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@{user.firstName, default=Placeholder}"/>

如果要使用带空格的文本作为占位符,则可以使用单引号('),反引号(`)或&quot;

If you want to have text with spaces as placeholder you can use single quotes ('), back quotes (`) or &quot;

android:text='@{user.firstName, default="Placeholder text"}'
android:text="@{user.firstName, default=`Placeholder text`}"
android:text="@{user.firstName, default=&quot;Placeholder text&quot;}"
android:text="@{user.firstName, default=@string/placeholder_text}"

这篇关于Android Studio设计时数据绑定回退/默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆