开发者

Android: EditText doesn't get ellipsized

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="horiz开发者_高级运维ontal"
            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?


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.


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


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"


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.


<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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜