2013-10-09 20 views
5

不幸EditTextの作業で楕円を作ることができません。テキストが長すぎると、テキストの最後に3つのドットを置くことも可能ですか? TextiViewでは完全に機能しますが、EditTextでは機能しません。いくつかのアイデア?EditText省略記号(3つの点...)

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" 

答えて

0

(独自のビューを作成しない限り)EditTextでは不可能です。私は(singleLine EditTextの)デフォルトの動作は、ビューに収まらないときにテキストを横にスクロールできることだと思います。

13

テキストを編集するには、このプロパティを設定します。 ElipsizeはあなたがEditTextを拡張する新しいクラスを記述する必要がある

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

ありがとう、完璧にうまくいった:) –

+0

それは動作します。 scrollHorizo​​ntallyプロパティとlinesプロパティを設定する必要はありません。 –

+2

android:editableプロパティは廃止されました。アンドロイド:inputTypeを使用することをおすすめします。しかし、私のテストによれば、それが存在すればもう動作しませんでした。android:inputType – Jacky

-2

無効エディットテキストと協力しています。たとえば、

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); 

       } 
} 

    } 
} 
9

属性を削除する必要があります。android:inputType属性を削除する必要があります。

inputTypeが定義されている場合、Ellipsizeは機能しません。

関連する問題