EditText - ellipsis (three points ...)

Unfortunately, I cannot make an ellipsis for EditText to work. Can you even put three dots at the end of the text when the text is too long? It works great for TextiView, but not for EditText. Some idea?

android:id="@+id/ed_email_personalInfo" android:layout_width="match_parent" android:layout_height="55dp" android:background="@color/transparent" android:ellipsize="end" android:ems="10" android:hint="@string/email" android:inputType="textEmailAddress" android:maxLength="64" android:paddingLeft="10dp" android:paddingRight="10dp" android:singleLine="true" android:textColorHint="@color/col9a9a9a" android:textSize="15.7sp" 
+6
source share
4 answers

Set this property to edit text. Elipsize works with disabled edit text

  android:lines="1" android:scrollHorizontally="true" android:ellipsize="end" android:singleLine="true" android:editable="false" 
+13
source

You need to remove the android:inputType .

Ellipse does not work if inputType is specified.

+9
source

Perhaps there will be no possibility in EditText (unless you create your own view). I think the default behavior (for singleLine EditText) is that you can scroll sideways when it cannot fit into the view.

0
source

You need to write a new class that extends EditText . eg:

 MyEditTextEllipsize extends EditText{ private String dotsString; private String storeString; public MyEditTextEllipsize(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(focused, direction, previouslyFocusedRect); if(focused) { setText(storeString); }else { String NOW = getText().toString(); storeString = NOW; if (NOW != null && getWidth() <= getTextSize() * NOW.length()) { dotsString = NOW.substring(0, (int) (getWidth() / getTextSize())) + "..."; setText(dotsString); } } } } 
-2
source

Source: https://habr.com/ru/post/955594/


All Articles