2

I set setOnApplyWindowInsetsListener to root view of application and get update on navigation bar changes, but insets.systemWindowInsetBottom is always 0

override fun onStart() {
    super.onStart()
    layoutMain?.setOnApplyWindowInsetsListener { v, insets ->
        layoutMain.updatePadding(bottom = insets.systemWindowInsetBottom)
        insets
    }
}

layoutMain is Constraint layout and root view group in MaincActivity

<androidx.constraintlayout.widget.ConstraintLayout 
android:id="@+id/layoutMain"
android:fitsSystemWindows="true" ... >

on more thing, I use following flag :

    window.addFlags(FLAG_LAYOUT_NO_LIMITS)

[using following tutorial :] also my another question for the same problem

Nininea
  • 2,671
  • 6
  • 31
  • 57

2 Answers2

0

After creating a sample project and following your reference tutorial i found followings things.

I found some reason of getting systemWindowInsetBottom value is zero.

  1. 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.

  2. 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;
                }
            });
        }
    }
Tariqul Islam
  • 680
  • 6
  • 14
0

From the View's source code, we know that only you set the flags (SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) that can impact the layout in relation to system UI, you can get the actual value。