4

Is there a way to have text displayed in the preview pane in Android studio but not in the actual app while running on the phone?

I currently use the android:hint attribute, which is quite useful to see how much space a TextView requires or what size the text will be.

The problem, however, is that in case no text is assigned to the TextView, the hint shows in the app.

Is there a way to have the text display only in android studio but not at runtime?

azizbekian
  • 60,783
  • 13
  • 169
  • 249
Tim John
  • 192
  • 2
  • 17

1 Answers1

16

It's tools:text="some text". This only will be visible in Android Studio.

From docs:

You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.

For example, if the android:text attribute value is set at runtime or you want to see the layout with a value different than the default, you can add tools:text to specify some text for the layout preview only.

enter image description here

Community
  • 1
  • 1
azizbekian
  • 60,783
  • 13
  • 169
  • 249