Very easy way to get the android soft keyboard height
Download the latest library via Gradle:
implementation 'cn.zmy.easykeyboardheight:1.0.0'
- init in Application#onCreate
@Override
public void onCreate()
{
super.onCreate();
EasyKeyBroadHeight.init(this);
}
- Any activity wants to know the height of soft keyboard, just implements
IKeyboardHeightAware
. When the soft keyboard is open or close,onKeyboardHeightChanged
will be call by EasyKeyboardHeight.
public class MainActivity extends AppCompatActivity
implements IKeyboardHeightAware
{
@Override
public void onKeyboardHeightChanged(int height, int orientation)
{
if (height == 0)
{
//keyboard is closed
}
else
{
//keyboard is open, it's height is `height`
}
}
}