demo效果

keyboardLayout.gif
GitHub上的源碼
介紹
KeyboardLayout 用于監(jiān)聽軟鍵盤的彈起和隱藏。
使用
KeyboardLayout 使用簡(jiǎn)單,只需將其加入到布局文件即可,無(wú)其他使用限制,KeyboardLayout只是充當(dāng)一個(gè)布局監(jiān)聽器的作用,即可實(shí)現(xiàn)對(duì)整個(gè)布局樹進(jìn)行監(jiān)聽。
對(duì)于Android Studio用戶,可添加:
compile 'com.hz.android.keyboardlayout:library:1.0'
- 布局文件
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
......
<com.hz.android.keyboardlayout.KeyboardLayout
android:id="@+id/keyboard_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
......
</android.support.constraint.ConstraintLayout
- 設(shè)置監(jiān)聽
KeyboardLayout keyboardLayout = (KeyboardLayout) findViewById(R.id.keyboard_layout);
keyboardLayout.setKeyboardLayoutListener(new KeyboardLayout.KeyboardLayoutListener() {
@Override
public void onKeyboardStateChanged(boolean isActive, int keyboardHeight) {
if (isActive) { //軟鍵盤彈起
//do something
} else { //軟鍵盤隱藏
//do something
}
}
});