I have used android:windowSoftInputMode="adjustResize" in the manifest to prevent keyboard from hiding the activity button. It works, but when keyboard opens, my button moves up. It is a bit jumpy, I wanted to know - can I have any animation for that to transition smoothly?
<activity
android:name=".Activity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
The method
setSoftInputMode(int)
cannot be overrided, its implementation is insideWindow
class and I don't think that's possible to replace the current window by your own. You cannot manage this fromWindowManager
too.You could create a listener on a
ViewGroup
and catch the modification's layout when theSoftKeyboard
is opening and closing. Indeed, when the SKB shows up, the container's layout redraws and changes its height. From this event, you could manage to set anAnimation
on views child and make a smooth effect.Edit: The solution by using a
GlobalLayoutListener
on the rootview is also possible instead of (the solution presented below:) creating a custom viewgroup class.You have to create your own viewgroup and make it as a parent container in the layout. It'll implement an interface which will be handled in the UI class (
Activity
,Fragment
, whatever). I found this blog to detect the events on SKB for (~)all versions. According to it, here's the viewgroup's class to handle the height's changes:Now, you've to add this viewgroup in layout (eg
<com.package.name.ContainerViewHandler .../>
). Then, you must implement the above interfacesetKeyboardStateListener
in the activity, like the following:Thus, you can manage different animations to handle and prevent the button to "jump" directly above the SKB. To test this out, I try to reproduce a bounce effect:
This how my implementation looks like:
I begin by setting two animations (a1, a2) in the first callback:
4xbutton's height
) and up to20dp
above it,20dp
and return to0dp
(normal position).And two others (b1, b2) in the second callback:
30dp
at top and go down to30dp
outside the parent container,30dp
out to0dp
(the initial position).PS: don't forget to use
adjustResize
in the Manifest and to make the content (eg edittexts in my tests)above
the footer button which hasalignParentBottom
to true.