Android_靠谱的监听软键盘状态的方法



public class MyActivity extends AppCompatActivity {

/**
* 当前界面中的软件盘的状态
*/
private boolean isKeyBoardOpen = false;
/**
* 监听软键盘状态
*/
private void addOnSoftKeyBoardVisibleListener() {
final View decorView = getWindow().getDecorView();
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
isKeyBoardOpen = (double) (rect.bottom - rect.top) / decorView.getHeight() < 0.8;
}
});
}
}
上一篇:【转】hibernate缓存:一级缓存和二级缓存


下一篇:UVA 11383 Golden Tiger Claw 金虎爪(KM算法)