I am working with android layout in which when I am hiding Proceed to Payment Button as well as Bottom View when Key board is showing, similarly when user press back or done Button in Keyboard keyboard will hide now mean time I am showing save address Button also Bottom View, To check the visibility of key board I am using following solluation and its working fine but the Problem is when KeyBoard hide it take jerk as layout recize
softKeyboardStateWatcher = new SoftKeyboardStateWatcher(mBinding.activityRoot);
softKeyboardStateWatcher.addSoftKeyboardStateListener(new SoftKeyboardStateWatcher.SoftKeyboardStateListener() {
@Override
public void onSoftKeyboardOpened(int keyboardHeightInPx) {
mBinding.actionProceedToPayment.setVisibility(View.GONE);
mHomeActivityImplementation.handleBottomTabs(false);
}
@Override
public void onSoftKeyboardClosed() {
mBinding.actionProceedToPayment.setVisibility(View.VISIBLE);
mHomeActivityImplementation.handleBottomTabs(true);
}
});
As showing in above code
when keyboard show layout then a glitch will occur as layout
is resizing,to avoid this I use onPostDelay()
as shown below
@Override
public void onSoftKeyboardClosed() {
mBinding.activityRoot.postDelayed(new Runnable() {
@Override
public void run() {
mBinding.actionProceedToPayment.setVisibility(View.VISIBLE);
mHomeActivityImplementation.handleBottomTabs(true);
}
}, 100);
}
but still facing same problem. I also apply CountDownTimer()
but problem not solved and Is there any method to avoid this jerk ?
First off- that library you're using, SoftKeyboardStateWatcher is not reliable. The functionality you need isn't exposed in the Android framework. Its making a guess, and there's many situations where it will be wrong and say a keyboard exists when it doesn't, and vice versa. So any code that relies on that class will be buggy. My suggestion would be not to provide this type of functionality at all, as how well it works will depend on device, OS version, keyboard used, etc.
Secondly, I don't think jerk is avoidable using that library. Its guess at when a keyboard is shown won't inform you until well after the keyboard expansion is done. So you're going to be waiting until the keyboard changes, then making additional changes. That will always cause jerk. The only thing you can do is animate the buttons in rather than just setting the visibility.