fitsSystemWindows on Fragment, Activity and DrawerLayout combination

浪尽此生 提交于 2019-11-30 16:05:43

So, the problem is, that the when the content is being changed, system will no longer dispatch those insets to the view hierarchy.

This can be easily solved with ViewCompat.requestApplyInsets(View) API. That would force the system to dispatch WindowInsets once again.

Ask that a new dispatch of View.onApplyWindowInsets(WindowInsets) be performed. This falls back to View.requestFitSystemWindows() where available.

So, in your example performing this changes would result in expected behavior:


    private void replaceFragment() {
      getSupportFragmentManager().beginTransaction()
          .replace(R.id.content, new MainFragment())
          // NOTE, we are performing `commitNow()` instead of ordinary `commit()`,
          // Because we want this commit to happen sychronously/immediately
          .commitNow();

      // Ask the framework to dispatch window insets once more to the root of your view hierarchy
      ViewCompat.requestApplyInsets(findViewById(R.id.drawer));
    }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!