AndroidKeyboardWatcher
介绍:
一个可以监听软键盘的打开或者关闭的库。
运行效果:
使用说明:
确保你在AndroidManifest.xml中为Acitivty配置了adjustResize windowSoftInputMode:
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize" />
在Activity.onCreate() 方法中绑定KeyboardWatcher,为了防止内存泄漏,请确保在onDestroy()方法中解绑。
public class MainActivity extends Activity implements KeyboardWatcher.OnKeyboardToggleListener {
private KeyboardWatcher keyboardWatcher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
keyboardWatcher = KeyboardWatcher.initWith(this).bindKeyboardWatcher(this);
}
@Override
protected void onDestroy() {
keyboardWatcher.unbindKeyboardWatcher();
super.onDestroy();
}
@Override
public void onKeyboardShown(int keyboardSize) {
}
@Override
public void onKeyboardClosed() {
}
}
下载
Java code
如果你不像在项目中添加依赖,只需拷贝 KeyboardWatcher.java的源码就可以了。
Library dependency
dependencies {
compile 'com.azimolabs.keyboardwatcher:keyboardwatcher:0.1.2'
}
已下载
0