View decorView = getActivity().getWindow().getDecorView();
View contentView = getActivity().findViewById(Window.ID_ANDROID_CONTENT);
decorView.getViewTreeObserver().addOnGlobalLayoutListener(getGlobalLayoutListener(decorView, contentView));
private ViewTreeObserver.OnGlobalLayoutListener getGlobalLayoutListener(final View decorView, final View contentView) {
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
decorView.getWindowVisibleDisplayFrame(r);
int height = decorView.getRootView().getHeight();
int diff = height - r.bottom;
LogUtil.loge("flag", "---------------diff:" + diff);
if (diff != 0) {
if (contentView.getPaddingBottom() != diff) {
contentView.setPadding(0, 0, 0, diff);
}
} else {
if (contentView.getPaddingBottom() != 0) {
contentView.setPadding(0, 0, 0, 0);
}
}
}
};
}