I am currently experiencing a strange bug with EditText with the android:digits parameter.
Here is the XML of the EditText :
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:hint="#string/some_text"
android:imeOptions="actionDone"
android:singleLine="true"
android:digits="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ\\ "
android:maxLength="140"
android:textSize="#dimen/font_size_small"/>
As you can see, this EditText allows the user to type only alpha-numerics characters.
Now, if I try to use this EditText, the EditText is correctly filtering the chars i'm typing
but ... if I type some chars then directly followed by %, the previously typed chars are copied in the EditText !
Eg: I'm typing on my keyboard hello%%, the result in the EditText will be hellohellohello.
Has any of you already experienced such a bug ? Is it from the Android platform ? Should I report it or has it already been ?
For information, my device is a Nexus 4 with Android 4.3.
Thank you !
The problem is with the Android Keyboard (AOSP). I was trying it using SwiftKey and couldn't recreate it. I changed to the default keyboard and the problem occurs.
The problem occurs because Android Keyboard is trying to learn/suggest words you're typing in. I'm not sure if the bug has been reported, but you can avoid this problem by using android:inputType="textNoSuggestions"
Related
I created an EditText that only allows numbers as an input. It's a very simple EditText with nothing special:
<EditText
android:id="#+id/editTextAmount"
android:layout_marginTop="10dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:inputType="text"
android:digits="0123456789"
/>
I tried it on a few devices and it's working as expected, I can enter only numbers. The issue arise when using a Samsung Galaxy Note S10+ (with a Samsung keyboard, I think the issue comes from there). With that device when I focus the EditText the keyboard opens (with only number visible) but when I type something in the field nothing happens. I can press any key from the keyboard (enter key, numbers, ...) nothing changes.
I tried to change the input type programmatically in the activity, I tried to fiddle with the inputType (numberDecimal, numberSigned, both, ...) in any case it is simply not working. The interesting thing is that if I change the inputType to "text" and remove the digits restriction then it is working perfectly.
My question is: How can I limit the EditText input to numbers with a Samsung Galaxy Note S10+?
EDIT: Just to make it perfectly clear, I am asking this for a specific device! I already tried:
android:inputType="number"
And
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
And
any variation of those (numberDecimal, numberSigned, ...)
in Java class set input type like this
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
or if you want to do that from layout then set
android:inputType="number"
It seems to work well with this configuration:
android:digits="0123456789"
android:inputType="phone"
That's a good enough workaround for me.
Below code opens numeric Keyboard on some Samsung Devices , Devices include Samsung s7 Edge,A9.
<EditText
android:id="#+id/prdtName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/Product"
android:text="#={product.productName}"
android:singleLine="true"
android:background="#drawable/edittext"
android:padding="15dp"
android:layout_margin="10dp"
bind:font="#{AppConstants.OpenSansRegular}"
android:inputType="textCapWords"
/>
can you please add the android verion of the devices you tested on?
As I understand, you want to open keyboard and allow the user to enter just capital letters. There is multiple ways to do it :
android:inputType="textCapSentences" will work for sentences to request capitalization of the first character of every sentence.
android:inputType="textCapCharacters" to request capitalization of all characters.
android:inputType="textCapWords"to request capitalization of the first character of every word.
These can be combined with text and its variations like textPersonName , textPostalAddress, textShortMessage and more...
for example : android:inputType="textCapWords|textCapSentences" and android:inputType="textPostalAddress|textCapSentences"
check the documentation : https://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
Or you might do it programatically :
EditText input = (EditText).findViewById(R.id.ID);
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
You can also use android:capitalize, it works on some cases and should automatically capitalize what the user types.
android:inputType="none", which won't automatically capitalize anything.
android:inputType="sentences", Which will capitalize the first word of each sentence.
android:inputType="words", Which Will Capitalize The First Letter Of Every Word.
android:inputType="characters", WHICH WILL CAPITALIZE EVERY CHARACTER.
If all these suggestions doesn't work for you, it's a problem with samsung devices and with some specific android versions. Try to fix that from keyboard settings like suggested here: https://stackoverflow.com/a/31699306/12802591
I am using MaterialEditText library.
Though I tried removing the MaterialEditText library and using normal EditText also doesn't work.
The issue is When I try to put inputType="textPassword" or inputType="number" or inputType="numberDecimal" my editText doesnt take number as input.
I tried with multiple phones. What I got to know it works correctly in SAMSUNG phones and not in other phones.
AM I missing something?
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/mobile_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:hint="#string/mobile_number"
android:inputType="numberDecimal"
android:textSize="#dimen/font_size_sub_normal"
app:met_clearButton="true"
app:met_floatingLabel="normal"
app:met_floatingLabelTextColor="#color/colorPrimary" />
even if I use normal editText it doesn't work.
If I remove InputType than it works.
EDIT :
I just found that issue is with Google Keyboard. Everything works fine with samsung keyboard but inputType with Google Keyboard not working. Not working in the sense it is not taking numbers
Try to use solution provided by google (support library)
EditText with TextInputlayout
I am trying to make an EditText such that, when I click it, a keyboard containing ".com" appears, because a URL is to be entered into the EditText.
I tried to use this:
android:inputType="textUri"
but it is not working. How do I do it?
try this one
<EditText
android:id="#+id/edt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="textWebEmailAddress"
/>
android:inputType="textWebEmailAddress"
use this property for that.
You can use inputType as textWebEmailAddress or textEmailAddress. Specs say it is device dependent but honestly I did not find any difference. Purpose of using this is you can use the # and .com keys in the keypad. I tried both on samsung Galaxy S5 and keypad is the same.
I have a edit text, whose input type is number.
in emulator its working fine i.e, showing the num-pad as soft keypad.
but in the device its showing alphabets keyboard why?
<EditText android:layout_width="110dp"
android:layout_height="30dp" android:id="#+id/phone"
android:layout_alignParentRight="true" android:background="#drawable/edit_text_bg"
android:inputType="number" android:maxLength="10"
android:paddingLeft="4dp" android:textColor="#1b0a00"
android:layout_marginRight="8dp"/>
Thanks in advance....!
So from what i've observed setting the inputType to phone should solve the problem . But try a different device to check if ur code works by giving input as number before moving to this option .
I think you must change inputType
FROM :
android:inputType="number"
TO:
android:inputType="phone"
When you give the InputType as number there is a completely new keyboard that gets loaded very different to what you will get by pressing the corner button on your normal keyboard to get numbers . Only certain phones/android versions(i think 2.2+) have this separate keyboard . For the ones that dont have this , The normal keyboard is shown and manual switching has to be done .
It could be that the device you're testing has some sort of custom keyboard enabled by default that doesn't support a number pad. Try changing the keyboard settings to the standard keyboard on the device and see if it works.