After creating a sample project and following your reference tutorial i found followings things.
I found some reason of getting systemWindowInsetBottom
value is zero.
The value is depend on bottomNavigation
. If your system back button (Soft layer) overlap the bottomNavigation
or your bottomNavigation
is completely hide then you wuill get correct value of systemWindowInsetBottom
.
But if your bottomNavigation
visible and above from system soft bottom layer (back button,home button etc.) then you you will get 0.
The below example is showing when we get can zero and when we can get actual value.
if you add this line you will get some value because bottomNavigation not visible mBinding.getRoot().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
;
But if you remove that line or add this line you will get always zero.
mBinding.getRoot().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
So the vaue is depend on bottomNavigation visibility state
private ActivityMainBinding mBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
mBinding.getRoot().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
if (navHostFragment != null) {
NavigationUI.setupWithNavController(mBinding.bottomNavigation, navHostFragment.getNavController());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
mBinding.mainLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
Log.d("BottomTest", "padding: " + insets.getSystemWindowInsetBottom());
return insets;
}
});
}
}