I have a very weird, but consistent bug in my app with any standard Android keyboard that supports word predictions.
What I’m doing is that I call InputMethodManager.restartInput() after I evaluated the input of an EditText to show a different IME label (I check the current text with a TextWatcher and the set the label to ”Close” when the text is empty and to “Send” when it's not). Without calling restartInput() the IME label change is not taken over until the connection is otherwise renewed, e.g. by closing and reopening the keyboard again.
Now when I manually enter characters through the keyboard everything is fine as expected, labels are changed, key strokes are accepted, all good, but if I click on one of the predictions on some keyboard to paste the word, the second click on the prediction is lost (i.e. the word that should be pasted after I called restartInput()).
"Lost" means different things for different keyboards, SwiftKey for example keeps the first word underlined and then replaces that with the second word on click, while Google's keyboard just keeps the first word, ignores the second word completely and then continues with any next word.
This video shows the issue: https://puu.sh/v0WUo/8f9b3571ed.mp4
I click on “Test and the”, but the EditText only receives “Test the".
Has anybody seen this before? What am I doing wrong?
Related
Pressing Enter/Submit when the user focus is in the search creates a new line break rather than submitting the search.
This appears to only happen in an emulated environment with a physical keyboard.
The text input is androidx Jetpack Compose. I added the lines:
singleLine = true,
maxLines = 1,
to the OutlinedTextField, but all that did was prevent the textbox from expanding to the next line.
You can see in the screenshot below that the cursor moves to the next line. The cursor is there and is barely visible, but the only change was that the text field no longer expands to a second row:
Search works just fine with the on-screen keyboard, so that's not the issue. The issue only seems to be with external, physical keyboards.
Use an onQueryTextChanged on the searchView, and if you see a \n inserted delete it and trigger a search
I am using the android:digits option in my xml file:
android:digits="0123456789qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM"
When I input some characters and press the space-bar more than once from my device keyboard, then the space-bar works as a back-press event and is removed from the last character. But this should not work like this.
I don't want to allow white space and special characters in the edit text.
For Ex.
I am input text and again press spacebar more than one times then start remove from last character of word.
For ex. I was input "Hello" and i was press spacebar more than one time then "o" is removed from "Hello" did same process again.
I don't know how is it..
Your problem is most likely connected with soft keyboard "suggestion". You can add following property in XML.
android:inputType="textFilter|textNoSuggestions"
This made EditText behaving as expected in my case.
I have a screen with prefilled EditText. Whole it's text is selected via
editText.setSelection(0, editText.getText().length());
I do that so users are able to rewrite that text immediately, but when I hit some key it doesn't write it. It just deletes the selected text and then allows me to write. Is this an expected behaviour please?
editText.setSelection(editText.length());
will set the cursor to the end but it is to be noted there are two types of text that are set.
There is a hint (this will be wiped as soon as you press on it and it just sits in the background as a prompt to the user)
editText.setHint("Hey");
And then there is the text (this wont be wiped as soon as you press it)
editText.setText("Hey");
We observed a very strange bug with our app on the samsung s3 (running android 4.0.4 )
When typing text into a text area only the first character of each word would fill in, and only after you pressed space or picked a word from predictive text.
Typing 'what the hell ..' would result in 'w t h' being entered in the text area
Other text areas on different screens were working fine.
Turning off predictive text also fixed the issue.
Has anyone run into this issue before?
After further investigation we noticed that the problematic textarea wasn't changing appearance when it got focus - all our working text fields turned into square cornered fields with orange borders when clicked.
It turns out android does something odd and dynamically replaces your input fields with native elements as they get focus (hence the un-style-able orange bordered square bits :( ).
the kicker - if your input is inside an element with css absolute positioning this fails, and this also seems to mess up some forms of keyboard input. setting the element (and parent elements) to use position static fixes the issue.
We only saw this on the s3 when predictive text was on (this is the default..) but it may be on other devices.
Chalk this one up to Androids browser still being a mess..
Note that using this css hack to stop the native elements from being substituted:
input:focus { -webkit-user-modify: read-write-plaintext-only; }
caused ALL our text fields to have the problem outlined in this thread.
I had this problem too for a long time but have found that the key to stopping this glitch is to turn off the predictive text option in the keyboard settings every time you experience the 1st character input only problem. Personally, I like the predictive text being on 99% of the time, but some web pages (email providers mainly) aren't configured for predictive text to be used, so I keep predictive text on & just turn it off whenever I come across a web page where I experience the 1st character input only problem. To turn it on/off simply hit the cog button on the keyboard & where it says predictive text, just swipe the slider to the left, to the off position. This will allow whole words to be typed instead of just 1 character at a time. Then, once you've finished typing, you can hit the cog again & turn predictive text back on.
In the Google Maps app, there's a unique EditText that I'd like to reproduce. If you click "menu" then go to "directions", the "start point" field should begin with "My Location" as the text. The interesting part of this field is its behavior - you cannot edit "My Location" without completely deleting it first.
I have a few places where such behavior would be useful, but I can never quite fully reproduce this. There are three challenges involved with this behavior:
No matter what the user does, they cannot partially edit the field; it is always fully selected.
The keyboard directional keys, rather than moving around the EditText field, change focus.
When the user does choose to change the text, the behavior of #1 and #2 disappear and the field acts like a normal EditText.
Has anyone ever successfully reproduced this behavior?
Isn't it just a hint? Try setting
android:hint="My Location"
on the EditText in your layout resources.