final View activityRootView = findViewById(R.id.root_view); activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight(); Log.d(TAG,"TestKeyboardSandboxActivity.onCreate(...).new OnGlobalLayoutListener() {...}.onGlobalLayout() measured height::" +activityRootView.getMeasuredHeight()); Log.d(TAG,"TestKeyboardSandboxActivity.onCreate(...).new OnGlobalLayoutListener() {...}.onGlobalLayout() Height::" +activityRootView.getHeight()); if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard... relative.setVisibility(View.GONE); } else { relative.setVisibility(View.VISIBLE); } } });
`((ViewGroup) findViewById(android.R.id.content)).getChildAt(0)`
`heightDiff`