I need to programatically set EditText to display text like password and I also need this EditText to be single line.
I know how to make EditText to display text like password:
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
I also know how to display EditText on single line:
editText.setEllipsize(TruncateAt.END);
editText.setSingleLine();
I don't know how to combine these two. When I put these lines of code together, the EditText is not working. Even the software keyboard can't be displayed for it.
Does anyone of you guys know how to solve my problem? Thanks in advance for your answer(s).
I finally did it. For those who have the same problem the correct approach is to combine the two requests but in the different order than I did it before. So you should do:
editText.setEllipsize(TruncateAt.END);
editText.setSingleLine();
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
I hope this will help someone.
To make EditText conceal password characters, add the password attribute to the relevant element in your layout.
http://developer.android.com/reference/android/widget/TextView.html#attr_android:password
It can also be done programmatically
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
//.....
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
editText.setTransformationMethod(new PasswordTransformationMethod());
In XML file Type
android:singleLine="true"
Related
I have a long text which is required to float over edit text as the requirement says. I went through many such question here, but couldn't find the proper answer. How can we make that possible? I have tried using a '\n' with the hint string but it didn't work.
you can add \n without giving any space. example shown below
<string name="hint_manish">Hint first line\nHint second line\nHint third line</string>
The hint takes on the behavior of the Edittext it's related to.
Adding
android:inputType="text|textMultiLine"
will give you multiple line hint.
I have an EditText in my Android app. When I write something on it I don´t have the enter on my Keyboard and when the cursor goes to the final of the line doesn´t jump to the line below automatically. Which are the properties to change this? Thank you so much.
I answer my own question, it works
edittxt.setInputType(EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
edittxt.setMinLines(minLines);
edittxt.setGravity(Gravity.TOP);
edittxt.setVerticalScrollBarEnabled(true);
edittxt.setSingleLine(false);
Write these two lines in edit text xml
android:singleLine="false"
android:inputType="textMultiLine|textAutoCorrect"
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. :)
In my android application, I have some EditTexts. Those EditTexts will serve as password fields, but I've not marked them as password fields in the attributes, so that the font of hint text matches the font of hint in normal EditText widgets.
The problem I have though is that the password is revealed in the keyboard suggestion while it is typed, although it is hidden as I've used:
EditText.setTransformationMethod(new PasswordTransformationMethod());
What should I do to disable those suggestions?
I had already fixed it, but didn't have time to come and answer the question.
For anyone who is struggling with this, adding the following attribute to the EditText will work:
android:inputType="textNoSuggestions"
Did you use android:inputType="textPassword"
and android:password="true"?
I have an edittext for reply to email. i want to give three properties for edittext like Multiline, First character caps and disable word suggestions.
I gave like this in xml...
android:inputType="textCapSentences|textVisiblePassword"
I tried in code also... etMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
I am not able to give multiline....how can i achieve this
thanks
I found solution for this problem
Just set the following parameters in xml file..
android:inputType="textCapSentences|textVisiblePassword"
These are for setting first letter of sentence to caps and disable suggestions
and write following code in ur Activity
edittext.setSingleLine(false);
Try setting android:inputType="textMultiLine|textCapSentences|textVisiblePassword". What might be happening is that it is multiline but only one line is currently shown, in which you could say android:minLines="5" or so.