Search code examples
androidandroid-layoutandroid-edittext

Disable Enter in editText android


I have an EditText but I want only one line. I put lime this

<item name="android:maxLines">1</item>
<item name="android:minLines">1</item>
<item name="android:lines">1</item>

but doesn't work.

enter image description here

See my code:

<LinearLayout style="@style/linearInputEntryText">
    <LinearLayout  style="@style/subLinearLayout">
        <TextView style="@style/label" android:text="Last Name" android:id="@+id/textView2"/>
        <EditText style="@style/editTextEntryName" android:id="@+id/lastName"/>
    </LinearLayout>
    <View style="@style/linearInputEntryBlack" > </View>
</LinearLayout>

and styles:

<style name="editTextEntryName" parent="editTextEntry">
    <item name="android:maxLines">1</item>
    <item name="android:minLines">1</item>
    <item name="android:lines">1</item>
    <item name="android:layout_gravity">left</item>
</style>

Solution

  • Because of different Android versions, the best practice is to include these parameters at the same time:

             android:maxLines="1"
             android:lines="1"
             android:singleLine="true"
    

    If you don't, it will not work correctly on some devices.