EditText will not be written on one line

I am making a calculator, and user input is contained in an EditText. The input is entered via the buttons on the screen, so the Android keyboard is disabled. However, I want it to write all the input in one line and when the line reaches the border, it should be ellipse and then scroll horizontally so that you can reach the whole text.

I tried to do this by setting android: maxLines = "1" and android: ellipsize = "end", but this does not work. The text is still in multiple lines, but only one line is displayed, and you need to scroll vertically to see the other lines. I also tried using android: singleLine = "true", but this makes EditText completely unusable.

This is EditText XML:

<EditText android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end" android:background="@color/colorBlue" android:textAlignment="textEnd" android:textSize="40sp" /> 
+5
source share
2 answers

I think this will work for you. Let me know if this works.

 <EditText android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end" android:background="@color/colorBlue" android:textAlignment="textEnd" android:textSize="40sp" android:inputType="text" android:maxLines="1" android:lines="1" android:scrollHorizontally="true" android:ellipsize="end"/> 

This post can help you.

+9
source

For a single line in EditText you just need to set two properties:

 android:inputType="text" android:maxLines="1" 
+1
source

All Articles