singleLine
is/was used in xml layout files for TextView
and EditText
something like the following:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true" />
Some people on SO say singleLine
is deprecated, while other people still suggest using it. Sometimes it even seems necessary to use when maxLines="1"
doesn't work. (see here, here, and here)
The docs should be the place to go to answer this question, right? Here, they say:
This constant was deprecated in API level 3.
This attribute is deprecated. Use
maxLines
instead to change the layout of a static text, and use thetextMultiLine
flag in the inputType attribute instead for editable text views (if both singleLine and inputType are supplied, the inputType flags will override the value of singleLine).
However, in the TextView docs, there is no indication that it is deprecated, either for android:singleLine
or for setSingleLine
or for setTransformationMethod
. The same TextView docs, by comparison, do state that other things like STATUS_BAR_HIDDEN
and fitSystemWindows
are deprecated. So is the singleLine
deprecation an omission, was it "undeprecated", or what?
This question has been previously asked before but was not the main focus of the question (and was not answered).
In the official grepcode of
TextView
(v5.1.0 r1) :android:singleLine
is not annotated with@Deprecated
.I also see this in
setInputType
method:setInputType
overrides themSingleLine
value so.EDIT : This xml attribute is now officially deprecated. (since API 3?). It is now visible in AndroidStudio xml editor.
While Android Studio claims that it is deprecated, in reality we had an edit text which should allow itself to be only single-line.
Adding
maxLines="1"
made it allow newline characters, which is not suitable for our needs.So we went back to using
singleLine="true"
.Just for adding some more information to the discussion, Lint now has the following error:
"Combining
ellipsize
andmaxLines=1
can lead to crashes on some devices. Earlier versions of lint recommended replacingsingleLine=true
withmaxLines=1
but that should not be done when usingellipsize
.More info: https://issuetracker.google.com/issues/36950033"
So, I guess that
singleLine
is now, and I think we should come up with a new term... "deprecatedish"?Only providing
android:maxLines="1"
andandroid:minLines="1"
wont solve the issue of keyboardactionNext
related issue. Useandroid:inputType="text"
for the same.