监听键盘收起
<h1>监听键盘收起工具类</h1>
<h2>原理(监听view的高度变化)</h2>
<pre><code>final int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (!isSoftKeyboardOpened && heightDiff > 200) { // if more than 200 pixels, its probably a keyboard...
isSoftKeyboardOpened = true;
notifyOnSoftKeyboardOpened(heightDiff);
} else if (isSoftKeyboardOpened && heightDiff < 200) {
isSoftKeyboardOpened = false;
notifyOnSoftKeyboardClosed();
}</code></pre>
<h2>使用方法</h2>
<pre><code> SoftKeyboardStateHelper softKeyboardStateHelper = new SoftKeyboardStateHelper(secondcll.getEdit());
softKeyboardStateHelper.addSoftKeyboardStateListener(new SoftKeyboardStateHelper.SoftKeyboardStateListener() {
@Override
public void onSoftKeyboardOpened(int keyboardHeightInPx) {
//键盘打开
}
@Override
public void onSoftKeyboardClosed() {
//键盘关闭
}
});</code></pre>