Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative of singleLine attribute (Deprecated) TextInputEditText

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:

enter image description here

Is there any alternative way for this?

like image 522
Pratik Butani Avatar asked May 06 '16 19:05

Pratik Butani


3 Answers

The android:singleLine attribute has been deprecated since API Level 15. You can achieve the same behaviour by using android:maxLines, which allows you to specify an arbitrary number of lines. This is superior to android:singleLine, which restricts you to only allowing one line.

<TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:minLines="2"
     android:maxLines="2" /> <!-- can specify arbitrary number of max lines -->
like image 97
fractalwrench Avatar answered Nov 13 '22 04:11

fractalwrench


Always define input type for single line

ex : inputType="text"

You don't need to do anything else.

like image 22
Arihant Avatar answered Nov 13 '22 04:11

Arihant


android:singleLine is deprecated since API 3, you have to use android:maxLines instead (in your case android: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 that android:maxLines can't make:

e.g.

This will produce a scrolling horizontal text on one line if the text is selected.

<TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:singleLine="true"
     android:ellipsize="end"
     android:scrollHorizontally="true" />

Instead, this won't work:

<TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:maxLines="1"
     android:ellipsize="end"
     android:scrollHorizontally="true" />
like image 39
Giorgio Antonioli Avatar answered Nov 13 '22 04:11

Giorgio Antonioli