I recently used TextInputEditText
and I got lint error that singleLine
attribute is Deprecated
<android.support.design.widget.TextInputEditText
android:id="@+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/string_hint_dob"
android:lines="5"/>
</android.support.design.widget.TextInputLayout>
Getting strike-through as below:
Is there any alternative way for this or any reason to make it deprecated?
Following a commment of Juan José Melero Gómez, I would like to add more information:
If you are attempting to set an
imeAction
to yourEditText
such asactionSearch
, settingandroid:maxLines="1"
won't be enough. Addingandroid:inputType="text"
is mandatory if you want to see the search icon.Always define input type for single line
ex :
inputType="text"
You don't need to do anything else.
The
android:singleLine
attribute has been deprecated since API Level 3. You can achieve the same behaviour by usingandroid:maxLines
, which allows you to specify an arbitrary number of lines. This is superior toandroid:singleLine
, which restricts you to only allowing one line.use
android:inputType="text"
andandroid:maxLines="1"
togatherandroid:singleLine
is deprecated since API 3, you have to useandroid:maxLines
instead (in your caseandroid:maxLines="1"
).The reason of the deprecation is for its bad performance. Anyway the
singleLine
attribute will not be removed because it's still the only way to make some effects thatandroid:maxLines
can't make:e.g.
This will produce a scrolling horizontal text on one line if the text is selected.
Instead, this won't work: