Is there a way to detect when the keyboard is about to be presented in Android?
My problem is that I have a ListView with EditTexts in it. When the keyboard is about to be presented, these are quite often redrawn, causing an EditText that was JUST tapped to lose focus and require an extra tap.
My proposed solution is to monitor when the keyboard is about to be shown, check to see which view currently has focus, then after the keyboard is done being shown, restore focus to that view.
However, I have no idea how to detect when the keyboard is "about to be shown" in Android. How would I do this?
(I would also accept an alternative answer that addresses my actual problem: EditText losing focus when keyboard is displayed)
You could do it the other way, create an unique OnFocusChangedListener myListener and set it to all your EditTexts and put a switch inside and store which is the last view getting/losing focus
Related
I wrapped my form in a <ScrollView> and I set my manifest android:windowSoftInputMode="adjustResize" (default of react native). Now when I manually focus a field with my finger touch event, and the field is covered by keyboard, it successfully scrolls to the field I just pressed.
However, if I pragmatically focus the next field (refToTextInput.focus()), it is not scrolling to that next field (focus does happen). I need the scroll to happen.
How can I trigger the adjustResize again, so it scrolls into view the next field I focused?
Manual focus - good
Here is what happens on manual focusing the password field, screencast:
Programmatic focus - bad - fail
However if my focus is in the "username" field and then I do this.refToPassword.focus() on the onSubmitEditing of the username field. Focus moves to the password input, and the keyboard doesnt flash (this is perfect I don't want the keyboard to flash). HOWEVER, the scroll view doesn't scroll to this field. Here is screencast of programmatic focus:
This is not the exact solution that I am proposing. However, you might consider this as a workaround.
You might consider hiding the keyboard programatically and showing the keyboard again on requesting focus programatically in the next EditText field. So the complete pseudo code for requesting the focus in next field will be something like.
public void requestFocusToNextField(View view) {
view.requestFocus();
hideKeyboard();
showKeyboard();
}
Hope that helps!
I have two EditText views and one ImageView. My goal is to hide the ImageView when i am showing the keyboard (When the user have clicked on one of the EditText fields)
Then show the imageView again when the user have unfocused the EditText field or the keyboard is not visible anymore.
I have tried tons of different ways to do this. But nothing really works as intended. Do you guys have any idea how i could achieve this
Have you tried to detect if the keyboard is opened ? How do I Detect if Software Keyboard is Visible on Android Device?
Make debug and when is opened try to hide image . imageview.setvisibility (GONE)
if it does not work you can try to change layout
Make 2 layouts and switch visibility if the keyboard is open /closed
You can add a OnFocusChangeListener to the EditText,when you click the EditText,it will get focus,and then you can hide the ImageView.
<activity android:name="SearchResultsActivity"
android:windowSoftInputMode="adjustPan"/>
adjustPan:
The activity’s main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
regards! :)
You can do one thing, place UIView-> UIImageView -> UITextfield1-> UITextField2.Handle the UIImageView hiding state in textfield delegates which are Begin and End editing delegate methods
I'm using the v16 API and having problems with where the popup is being placed when the onscreen keyboard is displayed.
The first problem is that if the EditText is at the bottom of the screen, when I touch the field to open it for editing the popup is displayed below the control and the immediately covered as the keyboard appears. It doesn't reposition itself above the EditText until a keypress triggers my validation code to fire again on the new value.
The second problem is that when I close the keyboard and the ScrollView containing the text scrolls back down from where it positioned itself to show the EditText above the keyboard the popup remains placed on the upper half of the screen instead of where the EditText is until I touch something else on the screen (triggering the ScrollView to do a redraw???).
Unfortunately that popup has various problems like this :(
Perhaps a simple solution in your case is to forcibly invalidate the UI when the keyboard has displayed and dismissed? Can't recall if the Popup will reposition if the EditText is invalidated, but worth trying as the alternative may be to re-implement.
Checkout my android-formidable-validation lib on github, it re-implements...though has its own problems - if you go down that path, why not give me a hand with some contributions ;)
At first my EditText had the focus as soon as the app loaded the screen and I disabled that with
android:focusable="true"
android:focusableInTouchMode="true"
However, there is no way to lose focus after clicking the EditText. The focus is still there when I try to click outside of the text area. This also happens when I click on the EditText to change the value and press "Done" on the on screen keyboard. Does anyone know a way for me to accomplish this?
Focus only changes if you click on something else that can gain focus. Issue is: If you click on a button for instance you might not lose focus, unless you do what Mathew said. Problem with that is: A button whose focusableInTouchMode is set to "true", needs now to be clicked TWICE: Once for gaining focus and once for performing OnClick. A nagging issue, that was haunting me as well right now.
I'd like to highlight the text in an EditText when a keyboard opens for user input (this could be a hardware keyboard or the virtual keyboard).
Highlighting isn't my problem, my problem is a trigger to highlight. Is there a handler that gets executed when the keyboard appears on a specific View (in this case, my EditText)? Are there different handlers for hardware keyboard vs virtual keyboard?
As far as I know, you can't get notified of those things at that level. Why not just highlight it when the EditText gets focus? In practice this will generally mean that an IME is displayed.
In fact, there is already a method to do exactly this: setSelectAllOnFocus.