Android Why EditText ellipsize doesn't work? - android

I have added an EditText to my layout, but the ellipsize doesn't work. Can anybody help me? Thanks.
<EditText
android:layout_width="match_parent"
android:layout_margin="10dp"
android:singleLine="true"
android:ellipsize="end"
android:textSize="24dp"
android:layout_height="wrap_content" />

Ellipsize="end" wont work for editable EditText so you need to make the EditText as non editable to make it work. Use the following code
<EditText
android:layout_width="match_parent"
android:layout_margin="10dp"
android:textSize="24dp"
android:text="A long texttttttttttttttttttttttttttttttttttttttttttttt"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:singleLine="true"
android:layout_height="wrap_content"
tools:ignore="Deprecated" />

ellipsize maybe works only with
android:ellipsize="end"
android:singleLine="true"
and sometimes we add one more
android:maxLines="n"

Related

android:maxLength not working on EditText

Siduation
I was trying to limit the amount of characters in my EditText using the flag android:maxLength.
Code
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/someComponent"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/someComponent2"
android:background="#null"
android:fontFamily="sans-serif-medium"
android:inputType="textCapWords|textPersonName"
android:lineSpacingExtra="8sp"
android:maxLength="10"
android:maxLines="1"
android:scrollHorizontally="true"
android:textSize="16sp"
android:textStyle="normal"
/>
Problem
For some reason it doesn't seem to have any effect. I can enter as many Characters as i wish
Question
Can anyone explain why the EditText doesn't behave according to its flags? Are there any flags which interfere with android:maxLength?
EDIT
Problem was found. Had nothing to do with the EditText. Was related to some wrongly committed changes.
try this code
<android.support.v7.widget.AppCompatEditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/someComponent"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/someComponent2"
android:background="#null"
android:fontFamily="sans-serif-medium"
android:inputType="textCapWords|textPersonName"
android:lineSpacingExtra="8sp"
android:maxLength="10"
android:maxLines="1"
android:scrollHorizontally="true"
android:textSize="16sp"
android:textStyle="normal"
android:maxEms="10"/>

How to character-wrap in Android textview without using singleline?

I have a textview in xml file. When a text is set in java file, if the 2nd String is too long, for example: "Hello Worlddddddddddddddddddddddddddddddddddddddddddddd", the 2nd word is not visible. It should be only one line and should not use the android:singleLine How can I solve it? Thanks in advance for the help. :)
<TextView
android:id="#+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="#color/white" />
if you without using singline, you can set height and weight.
android:scrollHorizontally="false"
ex :
<TextView
android:id="#+id/text"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:scrollHorizontally="false"
android:layout_height="15dp"/>
Use the XML below or refer to this SO article as this is what you really need.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:ellipsize="end"
android:singleLine="true"
android:gravity="right|center_vertical"
android:maxLines="1"/>
You can use elipsize property of textview
<TextView
android:id="#+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:maxLines="1"
android:textColor="#color/white"
android:ellipsize="end" />

Single line EditText in Android

I am trying to make the edittext single line. The edittext does comes up as single line but on pressing enter it the cursor comes to the second line and I need to stop this. The singleLine attribute is deprecated so I do not want to use that.
<EditText
android:id="#+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawablePadding="5dp"
android:lines="1"
android:maxLines="1"
android:inputType="none"
android:scrollHorizontally="true"
android:paddingLeft="5dp"
android:textSize="12sp" />
Can someone let me know what am I goind wrong over here ?
Set android:inputType to something different than "none", use "text", "number" or whatever should be entered in the EditText. This way you can make the EditText single-lined. (Of course you shouldn't use "textMultiLine" then ;))
Use this
android:singleLine="true"
instead of,
android:lines="1"
android:maxLines="1"
Change,
android:inputType="none"
to
android:inputType="text" or android:inputType="number"
according to your requirement.
use this code :
<EditText
android:id="#+id/Et_loginEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/layout_bg"
android:hint="Email Address"
android:singleLine="true"
android:ellipsize="end"
/>
This alone is enough to make single line in EditText.
<EditText
android:id="#+id/fullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Full Name"
android:inputType="text"/>
android:inputType="text" alone solves the single line in EditText.
You need to choose your desired inputType as per your requirement.
change the android:inputType="none"
<EditText
android:id="#+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawablePadding="5dp"
android:maxLines="1"
android:inputType="none"
android:scrollHorizontally="true"
android:paddingLeft="5dp"
android:textSize="12sp" />
to
<EditText
android:id="#+id/txtSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawablePadding="5dp"
android:maxLines="1"
android:inputType="text"
android:scrollHorizontally="true"
android:paddingLeft="5dp"
android:textSize="12sp" />

actionDone for EditText without singleLine option

I need to set the actiondone for my edittext without set the singleLine oprions (i need the input in multiple line). How can i do it?
that's the code:
<EditText
android:id="#+edit_text/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Titolo"
android:imeOptions="actionNext"
android:singleLine="true" />
<EditText
android:id="#+edit_text/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Inserisci la nota"
android:singleLine="false"
android:imeOptions="actionDone" />
This worked for me :
<EditText
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="false" />
I have found a solution
Set on your view programmatically
mEditText.setRawInputType(InputType.TYPE_CLASS_TEXT);
mEditText.setImeActionLabel(getResources().getString(R.string.done), EditorInfo.IME_ACTION_DONE);
mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
The xml file will be:
<EditText
android:id="#+id/my_EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The solution was found here:
https://gist.github.com/Dogesmith/2b98df97b4fca849ff94
Since SingleLine = false/true is deprecated. Apply below code. It worked for me.
<EditText
android:id="#+id/my_EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:imeOptions="actionDone"/>

marquee text view animation

The marquee animation does not work, this is what I did.
<LinearLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:background="#drawable/bg_trans"
android:layout_alignParentBottom="true" android:orientation="vertical">
<TextView android:id="#+id/trackName"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:textColor="#android:color/white" android:textSize="18sp"
android:maxLines="2" android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true" android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:layout_gravity="center_horizontal" />
<TextView android:id="#+id/artistName"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:textColor="#android:color/white" android:textSize="18sp"
android:maxLines="2" android:ellipsize="marquee"
android:scrollHorizontally="true"
android:focusable="true" android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:layout_gravity="center_horizontal" />
</LinearLayout>
It works for the first textview but doens't work for the second. What am I doing wrong?
This works for me -
<TextView
android:id="#+id/capture_mode"
android:layout_width="200px"
android:layout_height="wrap_content"
android:text="This is a test of marquee on the text view in android."
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:singleLine="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
/>
The field marqueeRepeatLimit will set the number of repitions.
UPDATE: The width of the text view need to be hardcoded to a specific value, you can set it to wrap_content. In such cases the marquee will still work just that it will have some blank space after the end the text and before it starts to display the text again. (Think Digital signboards, they have some gap in the display before displaying the next item.)
Other then what is mentioned above you also need to add
txtView.setSelected(true)
worked for me adding this line

Categories

Resources