EditText without auto-correction, etc - android

My EditText needs to accept input consisting of partial words, names, etc. At least on my HTC Desire, this is difficult since the keyboard wants to suggest and/or correct some entries (e.g., changes "gor" to "for"). I tried setting textNoSuggestions on the view, but that doesn't fix it.
Any simple solution to this?

Try this:
android:inputType="textFilter"
If that doesn't work, try:
android:inputType="textFilter|textNoSuggestions"

You can do this from the code. Set the input type of the EditText like below:
txtEmail = (EditText) findViewById(R.id.txtEmail);
txtEmail.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
For a list of all the available input type options see
http://developer.android.com/reference/android/text/InputType.html

The other suggestions are correct, but SwiftKey has decided it will ignore the inputtype values "in response to user requests". While I agree this is a bad idea since it contradicts the Google guidelines and developers usually have a good reason for disabling auto-correction (like username fields, family names and so on), it still is the most used keyboard application for Android devices, so this can be a big problem.
The workaround is to use either
android:inputType="textVisiblePassword"
or
.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

Try this if you want a multi-line EditText without displaying the underlines (auto correct):
myEditText.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Here's XML for that: android:inputType="textNoSuggestions|textMultiLine".

Related

Show comma instead of dot - Keyboard

Is there a way to get a comma for edittext instead of dot. My Keyboard is german, device is samsung.
looking for solution via XML not extra listeners.
So far i have tried
1.
android:digits="0123456789,"
android:inputType="number"
android:digits="0123456789,"
android:inputType="numberDecimal"
android:inputType="numberDecimal"
nothing seems to work, and I still get dot. I have gone through other similar questions but they suggest managing it by adding listener to edittexts. I have a lot of editText and it will be much additional/unnecessary work. There should be an XML simple solution to this.
Also tried
val input = EditText(requireContext())
input.keyListener = DigitsKeyListener.getInstance("0123456789.,")
EditText input = new EditText(THE_CONTEXT);
input.setKeyListener(DigitsKeyListener.getInstance("0123456789,"));

How to set input mask for EditText with regular expression? [duplicate]

Is there a way I can specify an input mask to the EditText control in Android?
I want be able to specify something like ### - ## - #### for a Social Security Number. This will cause any invalid input to be rejected automatically (example, I type alphabetical characters instead of numeric digits).
I realize that I can add an OnKeyListener and manually check for validity. But this is tedious and I will have to handle various edge cases.
Try using an InputFilter rather than an OnKeyListener. This means you don't have worry about tracking individual key presses and it will also handle things like pasting into a field which would be painful to handle with an OnKeyListener.
You could have a look at the source of the InputFilter implementations that come with Android to give you a starting point for writing your own.
The easiest way I know to use a mask on EditText in your Android programs in Android Studio is to use MaskedEditText library (GitHub link).
It's a kind of custom EditText with Watcher that allows you to set a hint with different color (if you want it will be available even when user already started to type), mask and it's very easy to use :-)
compile 'ru.egslava:MaskedEditText:1.0.5'
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="#+id/phone_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:typeface="monospace"
mask:allowed_chars="1234567"
mask:mask="###-##-##"
app:keep_hint="true"
/>
And that is!
You could take a look at the android.telephony.PhoneNumberFormattingTextWatcher class. It masks a phone number text input with the ###-###-#### pattern.
String phoneNumber = "1234567890";
String text = String.valueOf( android.telephony.PhoneNumberUtils.formatNumber(phoneNumber) ); //formatted: 123-456-7890
editTextMobile.setText(text); //set editText text equal to new formatted number
editTextMobile.setSelection(text.length()); //move cursor to end of editText view
Use this in an onKey function for delicious on-the-fly bunny sex with formatted phone numbers.
This site gives a good 2 classes that help with masking that I found quite useful.
You need to use the items in the comments to improve it. But worth adding to your program for ease of masking your EditText views for many masks.
you can use this efect in EditText

how to disable spellcheck Android edittext

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. :)

Android: inputType none and physical keyboard

I have a problem with TextEdit,
if I do editText.setInputType(InputType.TYPE_NONE); the user is not able to type anything.
Anyway, if there is a physical keyboard attached, then the user can type by using it (of course the soft keyboard doesn't work).
Is there any way to fully disable editing on a EditText?
PS: I need to do that programmatically at runtime
Try
android:editable="false"
in xml layout file
android:editable="false" is deprecated ,prefer not to use it.
Another solution to this that I used is given below
first_password_EditTextBox = (EditText) findViewById(R.id.editText1);
first_password_EditTextBox.setEnabled(false);

Masked Input Using EditText Widget in Android

Is there a way I can specify an input mask to the EditText control in Android?
I want be able to specify something like ### - ## - #### for a Social Security Number. This will cause any invalid input to be rejected automatically (example, I type alphabetical characters instead of numeric digits).
I realize that I can add an OnKeyListener and manually check for validity. But this is tedious and I will have to handle various edge cases.
Try using an InputFilter rather than an OnKeyListener. This means you don't have worry about tracking individual key presses and it will also handle things like pasting into a field which would be painful to handle with an OnKeyListener.
You could have a look at the source of the InputFilter implementations that come with Android to give you a starting point for writing your own.
The easiest way I know to use a mask on EditText in your Android programs in Android Studio is to use MaskedEditText library (GitHub link).
It's a kind of custom EditText with Watcher that allows you to set a hint with different color (if you want it will be available even when user already started to type), mask and it's very easy to use :-)
compile 'ru.egslava:MaskedEditText:1.0.5'
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="#+id/phone_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:typeface="monospace"
mask:allowed_chars="1234567"
mask:mask="###-##-##"
app:keep_hint="true"
/>
And that is!
You could take a look at the android.telephony.PhoneNumberFormattingTextWatcher class. It masks a phone number text input with the ###-###-#### pattern.
String phoneNumber = "1234567890";
String text = String.valueOf( android.telephony.PhoneNumberUtils.formatNumber(phoneNumber) ); //formatted: 123-456-7890
editTextMobile.setText(text); //set editText text equal to new formatted number
editTextMobile.setSelection(text.length()); //move cursor to end of editText view
Use this in an onKey function for delicious on-the-fly bunny sex with formatted phone numbers.
This site gives a good 2 classes that help with masking that I found quite useful.
You need to use the items in the comments to improve it. But worth adding to your program for ease of masking your EditText views for many masks.
you can use this efect in EditText

Categories

Resources