Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...