我想在軟鍵盤彈出窗口中隱藏操作欄。我已經使用下面的代碼來獲得結果的代碼。但是當我想回去時,應用程序崩潰。我已經包括在哪一行,我也收到了錯誤。請通過這個指導我。在軟鍵盤上隱藏操作欄彈出片段
在此先感謝。
私人無效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
}
});
}
試一下:[http://stackoverflow.com/questions/15327208/how-to-show-hide-actionbar-when-clicked-on](http://stackoverflow.com/questions/15327208/how-to-show-hide-actionbar-when-clicked-on) –