<span style="font-size:18px;">public class SoftInputObserver implements ViewTreeObserver.OnGlobalLayoutListener {
private View mRootView;
public SoftInputObserver(View rootView) {
mRootView = rootView.getRootView();
mRootView.getViewTreeObserver().addOnGlobalLayoutListener(this);
}
@Override
public void onGlobalLayout() {
final int softKeyboardHeight = 100;
Rect r = new Rect();
mRootView.getWindowVisibleDisplayFrame(r);
DisplayMetrics dm = mRootView.getResources().getDisplayMetrics();
int heightDiff = mRootView.getBottom() - r.bottom;
if (heightDiff > softKeyboardHeight * dm.density){
Toast.makeText(mRootView.getContext(), "show", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mRootView.getContext(), "hide", Toast.LENGTH_SHORT).show();
}
}
}</span>
android 监听软键盘的显示与隐藏
最新推荐文章于 2020-06-29 19:47:59 发布