Edittext with ellipsis

Asked

Viewed 61 times

0

In Edittext,

when text cannot be displayed completely and lose focus,

has some tag that can be set so that it displays the text with ellipsis?

2 answers

0

You need to do it this way in XML

<EditText
        ...
        android:maxLines="1" />

And then you need to put in Java

String text = edit_text.getText().toString();

if(text.length() > 8){
   edit_text.setText(text.substring(0, 8) + "...");
}

With this if it gets bigger than 8 characters will put the ... at the end

  • I couldn’t make it work, the layout type Edit is inserted does right?

  • I edited my answer with some complements, I had not seen that the other method I passed you was discontinued by Google

  • How do I know in which position I should truncate the text so that the result (counting ...) is in the visible area of Edittext?

  • Keep putting characters in the text="" of the XML until you notice that it arrived at the end, it was the most "smart" thing I could think of

0

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if(view.hasFocus()){
                    // se tá com foco, então pôe os "..." no texto
                } else {
                    // se tá sem foco, então mostra o texto inteiro
                }
            }
        });
  • I need to have the ellipsis in the text when Edit is without the focus to indicate that the text is not totamente visible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.