Can I specify a string to be shown in the layout preview in Android studio, e.g. for a TextView? ( Lorem ipsum ...)
It would be very helpful to be able to do that to see some text in the layout editor, e.g. to see if the textsize is correct etc.
Found the answer myself just now:
android:text="@{user.name, default=JOHN_DOE}"
As explained at the very bottom of this page:
http://developer.android.com/intl/es/tools/data-binding/guide.html
Drawback: Not sure how to use strings with spaces.
http://tools.android.com/tips/layout-designtime-attributes
1.) Add tools namespace in your root node:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
2.) Add a tools:text attribute:
<TextView
tools:text="John Doe"
Drawback: You need to add the tools namespace to your root node.
You need to use tools:text
Add the tools namespace to your root element.
xmlns:tools="http://schemas.android.com/tools"
Then the tools:text attribute as below.
Whether you are using DataBinding
or not it doesn't matter, tools:text
will work to see text during layout preview.
For more info see https://developer.android.com/studio/write/tool-attributes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With