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,"));
Related
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);
I have an edittext field. As I type and characters exceed the maxlength of it there appears a new row to continue typing. However, I want to avoid this behavior since there is map below it which is going down relatively.
I don't want to restrict the maxlength as well.
Can someone explain how do I solve this problem?
define following parameters in your xml under the edittext tag:
android:singleLine="true"
Correct me if Im wrong, but is't singleLine="true" depricated?
android:lines="1"
Just wondered, am I the only one to encounter this "strange" behavior.
When placing an EditText inside my activity and setting its
inputType="textPassword" as follow:
<EditText android:text="" android:id="#+id/EditText01"
android:hint="This is a hint" android:inputType="textPassword"
android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
The hint is displayed with bigger/double spaces between the words.
If I remove the inputType attribute it all goes back to normal.
I couldn't find a known issue regarding this behavior.
BTW- If you wonder why this is important (it isn't that much) try
putting two EditText widgets one below the other and set the inputType
of one of them to "textpassword" it doesn't look good.
Any idea on how to change the password or the other edittexts to use the same format ?
Thanks
PS. The question was added here first: http://groups.google.com/group/android-developers/browse_thread/thread/88738bb8d8046f6f but I didn't find an answer.
It happens because typeface automatically setted to monospace in case of password field. Setting android:typeface="normal" on password field doesn't helps.
Here code from TextView sources:
if (password) {
setTransformationMethod(PasswordTransformationMethod.getInstance());
typefaceIndex = MONOSPACE;
} else if ((mInputType&(EditorInfo.TYPE_MASK_CLASS
|EditorInfo.TYPE_MASK_VARIATION))
== (EditorInfo.TYPE_CLASS_TEXT
|EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)) {
typefaceIndex = MONOSPACE;
}
I can't find solution without implementing custom control with overriden typeface for hint.
P.S.: There is one solution, but it is not always acceptable - to set typeface to monospace on other EditText's.
Doing mEditText.setTypeface(Typeface.DEFAULT); fixes the problem for me.
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".
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