I have an EditText on a ScrollView in an Activity that has
android:windowSoftInputMode="adjustResize"
set.
I'm trying to anchor another (popup) view to that EditText, that appears if there is invalid text entered.
In order to anchor it,
EditView.getLocationOnScreen();
is called. So far, so good.
But I'm also dismissing the keyboard when the popup view appears, and if the EditText moved above the keyboard for text entry, then the EditText moves back down to the original position, but the popup appears where the EditText was (when the keyboard was showing).
If I log the location points with (getLocationOnScreen())for the EditText before and after keyboard dismiss, I can see they are the same.
My question - Is there a way to update the EditText location after the keyboard is dismissed?
If it helps, I'm using https://github.com/lupidan/PopoverView for the popup, but this to me is an issue outside of that code.
A better option than using a library that emulates a control from a different platform would be to use what is already built into the Android SDK. PopupWindow (docs links) would allow you to provide this same functionality and properly anchor the content to the EditText view. It can be passed a content view just like an activity or dialog, so the API is more consistent.
When you display a PopupWindow with showAsDropDown(), the framework will maintain the anchor position to the supplied view when operations like scrolling occur.
Related
Problem:
I have an edittext as a password field in a viewholderin a recyclerview. If the user clicks on it, the keyboard will appear below it.
Below the password field is a textview that gives feedback if the password the user has entered is valid. But this textview is not visible, because it is hidden because of the softkeyboard. Only after closing the softkeyboard, it is visible and he will see if the password he entered is correct.
Question:
Is there a way to let the softkeyboard scroll below the textview when the edittext is clicked or is there another way to make the password feedback visible to the user?
I would just put it in a scrollview. Then add bottom padding to the height of the soft board
In this case you have a recycler view. There is a Nested scrollview
but without seeing your code I cannot recommend it. You can also add padding to the recyclerviews last element with the passwords for the same effect. But this design is starting to sound funky.. Maybe its time to break this into its own fragment / activity?
That said this SO looks like your solution
What you're looking for is the Activity's windowSoftInputMode
attribute. You set this in your AndroidManifest.xml file, and give it
a value such as:
adjustResize: "The activity's main window is always resized to make
room for the soft keyboard on screen."
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." adjustResize will probably work for you, as long as you
wrap the layout in a ScrollView. It may have negative effects if you
have a bitmap image in the background, as it will be resized as well,
in which case you may want to use adjustPan instead.
or
More information
is available at the above link.
I have a popup that has a multi-line edit text and can appear at arbitrary position atop my application. Currently I have implemented it as a transparent activity. When the keyboard is shown over the popup, it jumps up and the current line is shown above the keyboard (I have the adjustPan flag set).
Now, I want the whole popup to go up and show above the keyboard, not only one line of text box. I was able to achieve this by moving focus to the whole layout when the EditText is focused, but then, well, the EditText loses focus, and I cannot type. Is there any other way way to do this? Or is there a way to focus a view without losing focus on another?
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
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 ;)
In my app,I have an edittext and a PopupWindow.
I want to show the popup once the user starts editing the text. but when I show the popup, it graps the focus from the edittext, and the virtual keyboard is dismissed (and I want it shown).
I tried creating the popup as not focusable, but then I can't select it after it's shown.
I also tried changing the focus and selection attributes of both edittext and from code after and before the popup is shown, but if the popup is created as not focusable, I can't select it after it's shown.
Is there a way of displaying a selectable popup along with editing the edittext?
You could try going in other direction. you have to control the input method editor (IME). every editable has an appropriate IME (also edittext has). You can control the IME - for example to be shown all the time not regarding to the state of edittext and dismiss it when you click on something or something happen.
You can ovveride the default editext implementation or you can control the IME at the viewgroup container/activity level.
http://developer.android.com/resources/articles/on-screen-inputs.html (read the APIs for controlling IMEs at the end).
hope this will help.