I have an edittext and I want to show 3 dots at the end when the text is longer than the edittext.
I found that there is a method setEllipsize so I've used that, but it is not working..
This is my code:
edt.setInputType(InputType.TYPE_CLASS_TEXT);
edt.setFocusable(false);
edt.setCursorVisible(false);
edt.setMaxLines(1);
edt.setHorizontallyScrolling(true);
edt.setSingleLine(true);
edt.setEllipsize(TruncateAt.END);
I've tried to add multiple parameters as you can see, but none of them are working.
Any more options I can try?
//try setting the Ems
edt.setMaxEms(5);
or
android:maxEms="5"
NOTE: you can adjust the ems size as how many chars you want to show.
Or in XML file set these for the editText
android:inputType="text"
android:maxLines="1"
SetEllipsize will work in TextView Try that
The issue here is that you're using setEllipsize with InputType = InputType.TYPE_CLASS_TEXT
For some reason these 2 don't work together :(
Related
When I write a text in an EditText it gets underline until I hit the space key. I've tried:
android:inputType="textNoSuggestions"
But it's not helping
If you are talking about the default 'underlining' of EditText, try setting its background to transparent.
try to add following lines in java code-
mEditText.setHorizontallyScrolling(true);
mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
If you need to support API 4 and below, use android:inputType="textFilter"
I want to remove the underlines from texts inside edittext fields.
How can I do that?
You can do it with following code. Just paste it in layout of EditText.
android:inputType="textNoSuggestions"
In order to get rid of spell checking you have to specify the EditText's InputType in the XML as the following:
android:inputType="textNoSuggestions"
However, if your EditText is multiline and also you need to get rid of spell checking,then you have to specify the EditText's InputType in the XML as the following:
android:inputType="textMultiLine|textNoSuggestions"
Minor addition to Chintan's answer - such (and other) combination is also allowed:
android:inputType="textCapSentences|textNoSuggestions"
Or if you want to just disable the red underline (and the autocorrect dialog), you can override the isSuggestionsEnabled() method on TextView.
This will keep the keyboard autocomplete working.
I just Added a line in for EditText
editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
and it worked fine for me.
So I was not able to find out any direct way of doing it. So went ahead with below workaround:
editText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
As the input type becomes a visible password, even if the spell check is enabled from the device settings, the Red underline won't appear. :)
I am testing it on Galaxy S2,there is no problem on it. But some devices looks like These screenshots- samsung Galaxy Note -.
What should I do? I cant find any topic about it?
<TextView ...
....
android:ellipsize="none"
..></TextView>
You need to set the ellipsize to none for that textview and there will be no "..."
Second thing this only happens when you have set your textview to SingleLine = true, so if you want to streatch your textview to multiline based on the text size then remove the singleline.
this is because the width of the textView is less and you are trying to add characters more than that,,
1) try to add more width to the textView
you can check out here how to set width
Well you can use android:layout_width = "wrap_content".
Alternatively you can use android:layout_width = "45dp" (or your defined width) and set the android:maxLines = "2". This will wrap the test in two lines and you will find what you are asking for.
instead of taking android:singleLine in XMl file you can declare it in your java code where you define your textView.
text.setSingleLine(true);
or in XML file
android:singleLine="true"
android:ellipsize="none"
I have created an EditText object dynamically but I haven't been able to create a multi-line EditText. I have tried this:
EditText et1 = new EditText(this);
et1.setHint("Enter Your Address");
et1.setSingleLine(false);
et1.setHorizontalScrollBarEnabled(false);
et1.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
et1.setLines(7);
Thanks.
Include this in your code:
et1.setMaxLines(maxlines);
Or you can set the specific height for the edit text.
If you want the text to wrap to the next line, add TYPE_CLASS_TEXT to the MULTI_LINE flag:
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
It is the line:
et1.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
that is the problem. Take that out.
setMaxLines doesn't matter much unless you want to set a max number of lines. You should also avoid setting the height to something specific. WRAP_CONTENT works great.
Even changing it to:
et1.setInputType(android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);
forces it to a single line edit, which seems odd.
This doesn't work either:
et1.setInputType(android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
which is really freakin irritating. Seems like an android bug...
You also might want to set the vertical scroll on and gravity so it can scroll up and down and starts in the top left.
et1.setGravity(Gravity.TOP|Gravity.LEFT);
et1.setVerticalScrollBarEnabled(true);
What worked for me is:
et1.setSingleLine(false);
et1.setHorizontalScrollBarEnabled(false);
et1.setVerticalScrollBarEnabled(true);
et1.setMinLines(minLines);
I am trying to create an EditText which toggles its state between read only and write mode.
My XML is as below:
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="4"
android:inputType="textMultiLine">
</EditText>
In my code i do the following :
textArea = (EditText) convertView.findViewById(com.pravaa.mobile.R.id.textArea);
//isEditable decides if the EditText is editable or not
if(!isEditable){
textArea.setInputType(InputType.TYPE_NULL);
}
//the view is added to a linear layout.
addView(textArea);
My issue is that the text does not get wrapped. Am i missing out on something? Kindly help me with this. I have also attached an image of my output.
The text set in the view is "12345678901234567 90123456789012345678901234567890 Nationwide Campaign New"
I was able to solve this issue by removing
android:inputType="textMultiLine"
To achieve the non-editable feature I used
setFocusable(false);
I guess that by calling this ...
textArea.setInputType(InputType.TYPE_NULL);
you override the flag InputType.TYPE_TEXT_FLAG_MULTI_LINE. Try calling this instead...
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
This line will make the text multi-line and will wrap the text
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
You'd probably also want to call setLines(n) to set the height of the textArea.
Try to replace:
editText.setInputType(InputType.TYPE_NULL);
with:
editText.setRawInputType(InputType.TYPE_NULL);
I would say that by using textArea.setInputType(InputType.TYPE_NULL); you remove the textMultiLine from your xml.
Just set textMultiLine isn't enough. Try this:
textArea.setHorizontallyScrolling(false);
textArea.setEllipsize(null);
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
What me helped was:
edtText.setInputType(InputType.TYPE_NULL);
edtText.setSingleLine(false);
It seems that the setSingleline Attribute in the XML file is ignored.