title: How can I apply setEllipsize(TextUtils.TruncateAt.END) on EditText in Android?
body: <p>The effect I want to achieve is shown as below:
  <a href="https://i.stack.imgur.com/0bwvl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0bwvl.png" alt="enter image description here"></a></p>
  
  <p>I expect that when the button is clicked and if the text length is longer than the <code>EditText's</code> width, the "..." be appended at the end.</p>
  
  <p>I tried in 2 ways. </p>
  
  <p><strong>One is like this:</strong></p>
  
  <pre><code> if (str != null &amp;&amp; edt.getWidth() &lt;= edt.getTextSize() * str.length()) {
        String dotsString = str.substring(0, (int)(edt.getWidth()/ 
                             edt.getTextSize()) - 1) + "...";
        edt.setText(dotsString);
       }
  </code></pre>
  
  <p>It looks fine, but when the text is mixed by different languages, Chinese and English characters, for instance, the result will not neet my expectation.</p>
  
  <p><strong>And the another way I tried is like this:</strong></p>
  
  <pre><code>TextView edtTv = (TextView) findViewById(R.id.edit);
  edtTv.setSingleLine(true);
  edtTv.setEllipsize(TextUtils.TruncateAt.END);
  edtTv.setText(edtTv.getText().toString());
  </code></pre>
  
  <p>But it does not work. </p>
  
  <p>I'm so confused! Any help will be appreciate.</p>