Using Android data binding, how do I specify dummy (or "default") text that will be displayed during layout preview in Android Studio?

Can I specify a line that will be displayed in the layout preview in Android studio, for example. for textview? (Lorem ipsum ...)

It would be very helpful to be able to do this in order to see the text in a layout editor, for example. to make sure the text matches the rule, etc.

+7
android android-databinding
source share
3 answers

Found the answer myself now:

Option 1:

android:text="@{user.name, default=JOHN_DOE}" 

As explained at the very end of this page:

http://developer.android.com/intl/es/tools/data-binding/guide.html

Drawback: don't know how to use spaces with spaces.

Option 2

http://tools.android.com/tips/layout-designtime-attributes

1.) Add the tool namespace to the root directory of the node:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 

2.) Add tools: text attribute:

  <TextView tools:text="John Doe" 

Disadvantage: you need to add the tool namespace to the root directory of the node.

+12
source share

You need to use tools:text

enter image description here

Whether you use DataBinding or not, it does not matter, tools:text will work to see the text while previewing the layout.

+2
source share

Yes, you can, for example, in TextView:

 android:text="Lorem ipsum" 
-2
source share

All Articles