简体   繁体   English

在 android 中以单一活动方法使片段布局全屏

[英]Make fragment layout fullscreen in single activity approach in android

I have been using the single activity approach and the navigation component.我一直在使用单一活动方法和导航组件。 My single activity has a bottom navigation view and one of the bottom view is a RecyclerView .我的单个活动有一个底部导航视图,底部视图之一是RecyclerView Clicking on one of its items opens a fragment.单击其中一项会打开一个片段。 Let's call it DetailsFragment I would like DetailsFragment to be fullscreen such that the bottom navigation view is not visible anymore.我们称它为 DetailsFragment 我希望 DetailsFragment 是全屏的,这样底部导航视图就不再可见了。 DetailsFragment also has its own toolbar which should hide the activity toolbar as well. DetailsFragment 也有自己的工具栏,它也应该隐藏活动工具栏。

I have read some suggestions to create another activity for DetailsFragment.我已经阅读了一些为 DetailsFragment 创建另一个活动的建议。 Doing so is an option which comes with many complex issues as I will have to rewrite all the communications between DetailsFragment and MainActivity.这样做会带来许多复杂的问题,因为我将不得不重写 DetailsFragment 和 MainActivity 之间的所有通信。

Best regards.最好的祝福。

This is how I managed to solve the problem:这就是我设法解决问题的方法:

navController.addOnDestinationChangedListener { _, destination, _ ->
        if (destination.id == R.id.detailFragment) {
            binding.bottomNavigation.visibility = View.GONE
            binding.toolbar.visibility = View.GONE
        } else {
            binding.bottomNavigation.visibility = View.VISIBLE
            binding.toolbar.visibility = View.VISIBLE
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM