Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText won't write into single line

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.

I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that 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" />
like image 973
leonz Avatar asked Jun 25 '16 14:06

leonz


Video Answer


2 Answers

Adding this line in the edittext make scrollable singleline text. android:inputType="textShortMessage"

like image 161
pz64_ Avatar answered Oct 18 '22 21:10

pz64_


I think this will work for you. Let me know if it 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 might help you as well.

like image 36
Charles Li Avatar answered Oct 18 '22 20:10

Charles Li