Get Android softkeyboard height _without_ "adjustResize" - android

I have an animation between two fragments. The second fragment will bring up a keyboard. As the keyboard will cover parts of the screen, I manually need to but a spacer view in there to adjust my view. Using android:windowSoftInputMode="adjustResize" will result in my transition-animation to be super laggy. Using adjustNothing on the other hand will make it smooth.
So is there any way to get the keyboard height without using adjustResize?
EDIT:
My question is different to f.e. Is there any way in android to get the height of virtual keyboard of device as I can't add adjustResize

Related

Trying not to show the buttons showing when I click in one of the EditText of the form

I'm working on an Android app with Android Studio. I have a form with several field and 2 buttons at the bottom to either validate or going back. The problem is that as soon as I click in one of the EditText of the form, the 2 buttons are following the keyboard.
How to prevent these 2 buttons to show up and force them to stay at the bottom of the page, hidden behind the keyboard. The form is in a ScrollView, which is in a ConstraintLayout. I tried many things like having my 2 buttons in the ConstraintLayout. Also outside in a RelativeLayout with constraint at the bottom of the parent... I also tried to use LinearLayout instead of the ConstraintLayout and weight each component but the buttons are still there. The only way I found is to use a vertical LinearLayout without weighting the components. But then I have the problem of not seeing the buttons if the screen is too small. I would like buttons to stay at the bottom.
Is it normal? Do I have to fix it from the code by hiding the buttons when focusing on one of the TextEdit, or by the layouts?
The other thing is that if I click on the last field ("Ville"), the form doesn't move and I still see the first 2 lines...
Thanks a lot for your help
On your manifest.xml you can set android:windowSoftInputMode to adjustPan.
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan" />
From Android documentation:
Don't resize the window to make room for the soft input area; instead
pan the contents of the window as focus moves inside of it so that the
user can see what they are typing. This is generally less desireable
than panning because the user may need to close the input area to get
at and interact with parts of the window

AdjustPan Android doesn't behave as I would expect

From what I could understand of the difference between AdjustResize and Adjust pan, it's that AdjustResize will change the height of all the components so that they can fit and squeeze into a "half screen" while AdjustPan will, only in the case where a view below the keyboard takes the focus, bring up this particular view so that it is accessible despite the keyboard.
However, in my case, I have a comment section which is a React Navigation view. In this view, I have a TextInput below it that must go up when the keyboard opens to write a comment. But when this TextInput goes up, it takes everything with it, including the elements of the previous view in the stack.
Picture from comment section (The gray above the keyboard is the textinput)
Picture from previous view in the stack if I go back (Only until the keyboard didblur event is sent and then everything returns to normal)
Why does the adjustPan seem to behave a bit like AdjustResize?
I've already tried to set AdjustNothing, but unfortunately it can't work because I don't receive keyboard events anymore.
I finally figured out where the problem was coming from.
I use
<SafeAreaInsetContext>
from the react-native-safe-area-context library because I need to do special management of the insets bottom for devices like iPhoneX or iPhone 11.
And in fact, when the Android keyboard opens, the insetBottom is redefined to take the keyboard size as well. So I had a padding on the bottom of my screen that was the size of my keyboard as soon as it opened. So the behavior is normal, and after correction, my AdjustPan behaves exactly as it should !

Keyboard from EditText destroing Layout

I have EditText, when i toutch this, keyboard will show, but instead of covering the bottom part of the application, it shifts all the elements at the top and makes them smaller, everything looks distorted ...
How do I display the keyboard so that it does not affect our layout?
Please check this Link:
You can add in your menifest for the activity you want to prevent such issue.
Also make sure if you are having a bit more content use scrollView as a parent.
And soft input mode as "adjustResize"
android:windowSoftInputMode="adjustResize"
or
android:windowSoftInputMode="adjustPan"
you can use as per your need.
adjustResize
to ensure that the system resizes your layout to the available space—which ensures that all of your layout content is accessible (even though it probably requires scrolling)—use this one.
adjustPan
The activity's main window is not resized to make room for the soft keyboard, and 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.
adjustNothing
Do nothing with layouts

How to prevent the background image to get resized on soft keypad launch while other screen components are movable on keypad launch

I have Login Activity with a background image and a frame layout.
The framelayout will be replaced by a relative layout which contains three edit text boxes in the relative layout and a button at relative layout's bottom i.e., alignParentBottom = true.
When I focus on any of the edit text boxes the keypad raises ans I want all of them to move accordingly and the button at bottom should be immediately above the keypad so I am using adjustResize in my manifest, but this is making my background image to get resized i.e., compressed and displaying it within the visible space of the screen.
I need my background image not to move while all other components should be moving according to the screen.
If I use adjustPan the button which is aligned at parent bottom is not getting placed above the keypad and is invisible behind the softpad.
Please help me in this regard if anyone knows the way to resolve this requirement.
Thanks.
Try adding android:windowSoftInputMode="stateVisible|adjustPan" to your activity in the manifest file.
Explained here:
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.
If it's top layer just instead of setting that layer background you set that activity custom theme with that background. That way it does't resize. At least that worked for me.

Get soft keypad to stop modifying my LinearLayout on display?

In my android application, I have an EditText. When I click in this field, the soft keyboard appears, expanding from the bottom of the screen. It seems to actually modify my layout, pushing contents upwards. When I dismiss the keypad, it retracts, and I see my layout re-expand to take up the space it previously occupied.
Is there a way to get the keyboard to simply appear "on top" of my layout, so that I don't get this somewhat unpleasant relayout animation? The EditText is pinned to the very top of the screen, so I don't have to worry about the keypad hiding it.
Thanks
By default, Android should be using "Pan and Scan", which would work more or less how you described. The keyboard is displayed over your view, and you can scroll your view in the background. If you override the windowInputMode for you Activity, or Android determines that your Activity is resizable (because of the presence of a resizable field... ListView, ScrollViews, etc), it may resize your view instead, and it sounds like that's what you're running into. To force it to Pan and Scan try adding:
android:windowSoftInputMode="adjustPan"
as an attribute to the Activity element in your xml layout.
There's a third option as well. You can specify that when an EditText is selected it will be edited in full screen mode. The other controls in your view will be hidden, the user will be presented with just the keyboard, an EditText control, and optionally some other limited controls. If your EditText doesn't require a lot of context from other elements of your view, it may prevent a cleaner user interface. For more details, see: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
Add:
android:windowSoftInputMode="adjustResize"
to your activity attr in manifest.xml. Hope it will help.
This questions seems to state a resize is not desirable. I had the same issue, but adding
android:windowSoftInputMode="adjustNothing"
to the manifest file instead solved my problem.

Categories

Resources