android - 在片段错误之间导航(BottomNavigationView Visibility)
问题描述
我试图使片段A中的BottomNavigationView
不可见,但在切换到片段B时可见,我尝试在整个导航过程中记录它们的生命周期并尝试visiblity
相应地设置但仍然无济于事......
我正在使用在Navigation
片段之间导航,导航是在adapter
传递onClick
视图的片段中完成的
编辑:我尝试使用onDestinationListener
错误:它随机工作
片段A:
lateinit var bvn: BottomNavigationView
val TAG = "TAG"
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_post_detail, container, false)
Log.d(TAG, "PDF: onCreateView")
val navController = findNavController(requireActivity(),R.id.nav_host_fragment)
navController.addOnDestinationChangedListener { _, destination, _ ->
if(destination.id == R.id.postDetailFragment) {
bnv.visibility = View.GONE
} else {
bnv.visibility = View.VISIBLE
}
}
...
...
return view
}
片段B:
lateinit var bvn: BottomNavigationView
val TAG = "TAG"
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_profile, container, false)
Log.d(TAG, "Profile: onCreateView")
val navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment)
navController.addOnDestinationChangedListener { _, destination, _ ->
if(destination.id == R.id.nav_profile) {
bnv.visibility = View.VISIBLE
Log.d(TAG, "Profile: bnv visible")
}
}
...
...
return view
}
片段A适配器:
...
...
override fun onBindViewHolder(holder: Viewholder, position: Int) {
// navigating to FragmentB...
holder.imageProfile.setOnClickListener {
val action = PostDetailFragmentDirections
.actionPostDetailFragmentToNavProfile(comment.publisher)
it.findNavController().navigate(action)
}
}
解决方案
推荐阅读
- hotkeys - 特殊字符的自动关键字短语
- gnuplot - 在 gnuplot 上绘制 10 行软 1000 个值
- regex - 如何从Pig中的方括号中提取字符串
- vue.js - 如何使用 Vue 和 axios 检索和显示单个记录
- node.js - Ffmpeg:此解码器不支持比特流
- api - V2 API - 访问权限不足
- amazon-web-services - 使用 NAT 实例从外部连接到 Elasticache
- angular - Angular 6 DataTables 最初显示但过滤器控件不起作用
- node.js - 将 vscode 调试器与 webpack 和 node.js 一起使用
- python - python pipe limited to 196608 ( 65536*3 ) with subprocess.Popen()