Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android singleLine vs maxLines

I thought singleLine="true" was equivalent to maxLines="1" but I see that the following pre-populated field from Android Studio has both. Is there a difference? Is there a known bug that causes both to be required?

<EditTextPreference
   android:key="example_text"
   android:title="@string/pref_title_display_name"
   android:defaultValue="@string/pref_default_display_name"
   android:selectAllOnFocus="true"
   android:inputType="textCapWords"
   android:capitalize="words"
   android:singleLine="true"
   android:maxLines="1" />

this is from the pref_general.xml file.

like image 375
Katedral Pillon Avatar asked Jun 16 '15 22:06

Katedral Pillon


People also ask

What is Android singleLine?

From Android website: singleLine: Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key.

What is EMS in Android Studio?

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.

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

Set The Text of The TextView You can set the text to be displayed in the TextView either when declaring it in your layout file, or by using its setText() method. The text is set via the android:text attribute.


1 Answers

From Android website:

singleLine:

Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key. The default value is false (multi-line wrapped text mode) for non-editable text, but if you specify any value for inputType, the default is true (single-line input field mode).

Must be a boolean value, either "true" or "false".

maxLines:

Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the maxLines attribute to apply.

Must be an integer value, such as "100"

Please note that singleLine has been deprecated since API 3 and maxLines should be used instead. So all you need really is

android:maxLines = integer // 1 for single line or add lines multiple as well.
like image 186
Kalimah Avatar answered Sep 29 '22 07:09

Kalimah