Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView: display text in preview only, not during runtime [duplicate]

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?

like image 920
Tim John Avatar asked Dec 07 '22 18:12

Tim John


1 Answers

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

like image 116
azizbekian Avatar answered Dec 10 '22 13:12

azizbekian