我正在尝试检测键盘何时显示为隐藏。我找到了这段代码,但它对我不起作用。
final View activityRootView = findViewById(R.id.LL_main);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
Log.d("login" ,
String.valueOf(activityRootView.getRootView().getHeight()) +
" - " +
String.valueOf(r.bottom - r.top) +
" = " +
String.valueOf(heightDiff));
}
});
我的'LL_main'是一个LinearLayout,它是主要的布局
的Manifest.xml
android:windowSoftInputMode="adjustPan|adjustResize"