Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Android widget should I use for a static text label?

I just want a simple non-editable text label but there doesn't seem to be a widget explicitly for it. The closest thing seems to be a android.widget.TextView. But the documentation says a "TextView is a complete text editor". That seems like overkill for a simple label. I don't want to bloat my application. Is there a more appropriate widget?

Or am I approaching this the wrong way? For example, let's say I'm building a settings screen, is there a layout I should choose which gives me labels for the properties so I don't have to specify widgets for the labels?

like image 522
Michael Osofsky Avatar asked Apr 25 '17 21:04

Michael Osofsky


People also ask

What is the name of label control in android?

It is TextView. It displays text to the user.

Which component can be used for displaying text in android Apps?

Label. Labels are components used to show text. A label displays text which is specified by the Text property.

Which method is used to set the text in a TextView?

In android, we can set the text of TextView control either while declaring it in Layout file or by using setText() method in Activity file.

What is EMS in android?

ems is a unit of measurement. The name em was originally a reference to the width of the capital M. It sets the width of a TextView/EditText to fit a text of n 'M' letters regardless of the actual text extension and text size. Eg : android:ems Makes the EditText be exactly this many ems wide.


1 Answers

Is there a more appropriate widget?

No.

I don't want to bloat my application.

You won't, unless you put a ton of text in it. While TextView has a lot of code, your process will already have access to that code, whether you use TextView or not. The only "bloat" would come from the actual heap space used by the TextView object itself (and objects that it holds).

For example, let's say I'm building a settings screen, is there a layout I should choose which gives me labels for the properties so I don't have to specify widgets for the labels?

Typically, we would use a PreferenceFragment, backed by a preference XML resource, instead of having any layout or widgets.

But, if you wanted to roll your own for some reason, use TextView for the labels.

like image 83
CommonsWare Avatar answered Sep 22 '22 07:09

CommonsWare