7

I have 2 EditTexts in a linear layout and they don't get ellipsized

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#696969"
            android:layout_marginBottom ="5px">

            <EditText
                         android:id="@+id/addressbar" 
                          android:layout_width="fill_parent" 
                          android:layout_height="wrap_content" 
                          android:layout_marginLeft ="2px"
                          android:layout_marginRight ="1.5px"
                          android:layout_weight="0.35"
                          android:textSize = "15sp"
                          android:singleLine="true"
                          android:editable = "true"
                          android:textAppearance="?android:attr/textAppearanceMedium"
                          android:ellipsize="end"
                          android:imeOptions="actionGo"

                           />
            <EditText android:id="@+id/googlebar" 
                          android:layout_width="fill_parent" 
                          android:layout_height="wrap_content" 
                          android:layout_marginLeft ="1.5px"
                          android:layout_marginRight ="3px"
                          android:background="@android:drawable/editbox_background"
                          android:layout_weight="0.65"
                          android:hint="Google"
                          android:textSize = "15sp"
                          android:singleLine="true"
                          android:ellipsize="end"
                          android:imeOptions="actionSearch"
                           />


            </LinearLayout>

what do you think?

Alex1987
  • 9,397
  • 14
  • 70
  • 92

6 Answers6

8

Set this property to edit text. Elipsize is working with disable edit text

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

or setKeyListener(null); This work for me fine in all Android platforms.

Mubarak
  • 1,419
  • 15
  • 22
5

I could see comment from many people that is Ellipsize works fine in TextView. But not in EditText! Actually I would say we need to have deep look at the EditText. Because EditText is child of TextView. EditText has capability to get input from user, which doesn't available on TextView. So EditText has KeyListener to observe EditText input key event changes. We have to disable this while you add ellipsize. So Your EditText won't be refreshed every time and you will not lose ellipsize feature.

editText.setKeyListener(null);
editText.setEllipsize(TextUtils.TruncateAt.END);
2

Ellipsize is broken: Ellipsize not working for textView inside custom listView

Bug Report: http://code.google.com/p/android/issues/detail?id=882

I had to do the following to get mine working...took a bit of fiddling

android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
Community
  • 1
  • 1
Will Tate
  • 33,439
  • 9
  • 77
  • 71
  • If you look at the two links provided people have managed to find a few work arounds, but none of them seem to work across the board. The combination I posted in my original answer seemed to work for me. – Will Tate Mar 04 '11 at 22:36
0

I have a solution, add this line to your EditText android:editable="false" The edittext will be ellipsized, but this property is deprecated, but event it's not deprecated, when this edittext is uneditable I don't know how to make it be editable again by java coding.

Leo
  • 1,433
  • 23
  • 40
0
<EditText
    android:id="@+id/et_task"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:textSize="25sp"
    android:ellipsize="end"
    android:editable="false"
    android:singleLine="true"
    tools:text="My Task text sfdsafdsasdfsadfsadfdsafasdfвыа"
    android:background="@android:color/transparent"/>
0

Try this, android:editable="false" or setKeyListener(null)

Reference: Ellipsize content of editText when disabled

Tyler2P
  • 2,324
  • 26
  • 22
  • 31