【发布时间】:2016-10-03 07:19:32
【问题描述】:
我想在软键盘弹出窗口上隐藏操作栏。我已经使用以下代码的代码来获得结果。但是当我想回去时,应用程序崩溃了。我已经包含在哪一行我也得到了错误。请指导我完成此操作。
提前致谢。
private void createView() {
mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect rect = new Rect();
//rect will be populated with the coordinates of your view that area still visible.
mRootView.getWindowVisibleDisplayFrame(rect);
int heightDiff = mRootView.getRootView().getHeight() - (rect.bottom - rect.top);
if (heightDiff > 100) {
// if more than 100 pixels, its probably a keyboard...
//keyboard visible
mBinding.healthRecordContainer.setVisibility(View.GONE);
((AppCompatActivity) getActivity()).getSupportActionBar().hide();
} else {
//keyboard not visible
mBinding.healthRecordContainer.setVisibility(View.VISIBLE);
((AppCompatActivity) getActivity()).getSupportActionBar().show(); // app crashes
} //java.lang.NullPointerException
}
});
}
【问题讨论】: