ソフトキーボードポップアップでアクションバーを非表示にしたい。私は結果を得るために次のコードをコードに使用しました。しかし、私が戻ってきたいとき、アプリがクラッシュします。私はどのラインにも私はエラーを取得しているが含まれています。これで私を導いてください。ソフトキーボードポップアップのアクションバーを非表示にする
ありがとうございます。
ます。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
}
});
}
それを試してみてください:[http://stackoverflow.com/questions/15327208/how-to-show-hide-actionbar-when-clicked-on](http://stackoverflow.com/questions/15327208/how-to-show-hide-action-click-on) –