Is the xml attribute singleLine deprecated or not in Android? Is the xml attribute singleLine deprecated or not in Android? android android

Is the xml attribute singleLine deprecated or not in Android?


I think the answer to your question is already in one of the SO posts you linked to. Unfortunately, the deprecation of singleLines is not a black-or-white matter.

It is deprecated, but it is not going anywhere anytime soon.

It was deprecated because its performance is poor, relative to its successor, maxLines. It uses SingleLineTransformationMethod to replace newlines and carriage returns in the String you place in the TextView, unlike maxLines, which "just" adjusts the height of the TextView based on the number of lines and does no String replacing.

This method of replacing characters also meant that singleLine could break in unexpected ways (e.g. if you use custom fonts). It was these performance and reliability issues that led to its deprecation.

However, it is not going anywhere because, as the SO post you linked to states, it is still in use by many old Android applications, and it is still useful sometimes (e.g. when you want to show the entire text on one line and ignore carriage-returns and newlines).

Do note that deprecation does not necessarily mean that an API is going away. It just means that its use is discouraged, but may be permitted.


The deprecated attribute was added in change d24b8183b9 which is nothing but a dump from Google's internal SCM:

auto import from //branches/cupcake/...@130745

As can be seen from the change core/res/res/values/attrs.xml diff adds the @deprecated doc comment, but core/java/android/widget/TextView.java diff does not alter anything from setSingleLine()'s doc comment.

Now without access to Google's internal SCM history, it is not possible to know what exactly caused above change in attrs.xml doc comment, but for your question

So is the singleLine deprecation an omission, was it "undeprecated", or what?

one possible answer is:TextView's single-line was neither deprecated, nor "undeprecated", but it was enhanced to take into account whether the view is editable, a password field or uses any other input type flag that affects single/multi-lineness.


In the official grepcode of TextView (v5.1.0 r1) :

android:singleLine is not annotated with @Deprecated.

I also see this in setInputType method:

boolean singleLine = !isMultilineInputType(type);// We need to update the single line mode if it has changed or we// were previously in password mode.if (mSingleLine != singleLine || forceUpdate) {    // Change single line mode, but only change the transformation if    // we are not in password mode.    applySingleLine(singleLine, !isPassword, true);}

setInputType overrides the mSingleLine value so.

EDIT : This xml attribute is now officially deprecated. (since API 3?). It is now visible in AndroidStudio xml editor.